From c5c733560f2a12996176b12f4f759e5000e33007 Mon Sep 17 00:00:00 2001 From: John Cote Date: Mon, 30 Dec 2019 23:04:48 -0500 Subject: [PATCH] minigame: fix more minigames --- otp/otpbase/PythonUtil.py | 20 +++++++++++++++++++- toontown/minigame/DistributedCannonGame.py | 2 +- toontown/minigame/PlayingCardGlobals.py | 2 +- toontown/minigame/Purchase.py | 1 + 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/otp/otpbase/PythonUtil.py b/otp/otpbase/PythonUtil.py index c7e2775..f943450 100644 --- a/otp/otpbase/PythonUtil.py +++ b/otp/otpbase/PythonUtil.py @@ -1,7 +1,8 @@ import builtins import sys +import math -__all__ = ['enumerate', 'nonRepeatingRandomList', 'describeException', 'pdir', 'choice', 'cmp'] +__all__ = ['enumerate', 'nonRepeatingRandomList', 'describeException', 'pdir', 'choice', 'cmp', 'lerp', 'triglerp'] if not hasattr(builtins, 'enumerate'): def enumerate(L): @@ -130,6 +131,21 @@ def pdir(obj, str = None, width = None, _pdir(obj, str, width, fTruncate, lineWidth, wantPrivate) print() +def lerp(v0, v1, t): + """ + returns a value lerped between v0 and v1, according to t + t == 0 maps to v0, t == 1 maps to v1 + """ + return v0 + ((v1 - v0) * t) + +def triglerp(v0, v1, t): + """ + lerp using the curve of sin(-pi/2) -> sin(pi/2) + """ + x = lerp(-math.pi/2, math.pi/2, t) + v = math.sin(x) + return lerp(v0, v1, (v + 1.) / 2.) + def choice(condition, ifTrue, ifFalse): # equivalent of C++ (condition ? ifTrue : ifFalse) if condition: @@ -158,5 +174,7 @@ def cmp(a, b): builtins.pdir = pdir builtins.isClient = isClient +builtins.lerp = lerp +builtins.triglerp = triglerp builtins.choice = choice builtins.cmp = cmp diff --git a/toontown/minigame/DistributedCannonGame.py b/toontown/minigame/DistributedCannonGame.py index 9b5626e..979e3f1 100644 --- a/toontown/minigame/DistributedCannonGame.py +++ b/toontown/minigame/DistributedCannonGame.py @@ -272,7 +272,7 @@ class DistributedCannonGame(DistributedMinigame): def getTowerPosition(self): yRange = TOWER_Y_RANGE - yMin = yRange * 0.3 + yMin = int(yRange * 0.3) yMax = yRange if self.DEBUG_TOWER_RANGE: if self.DEBUG_TOWER_NEAR: diff --git a/toontown/minigame/PlayingCardGlobals.py b/toontown/minigame/PlayingCardGlobals.py index acc02b2..5391394 100644 --- a/toontown/minigame/PlayingCardGlobals.py +++ b/toontown/minigame/PlayingCardGlobals.py @@ -45,7 +45,7 @@ def convertValueToGagTrackAndLevel(value): def convertRankToGagTrackAndLevel(rank): - track = rank % (ToontownBattleGlobals.MAX_TRACK_INDEX + 1) + track = int(rank % (ToontownBattleGlobals.MAX_TRACK_INDEX + 1)) level = rank / (ToontownBattleGlobals.MAX_TRACK_INDEX + 1) return (track, level) diff --git a/toontown/minigame/Purchase.py b/toontown/minigame/Purchase.py index ce24caf..43fa689 100644 --- a/toontown/minigame/Purchase.py +++ b/toontown/minigame/Purchase.py @@ -1,3 +1,4 @@ +from libotp import * from .PurchaseBase import * from direct.task.Task import Task from toontown.toon import ToonHead