class DestroyCreateArchetype: Archetype = Property.Archetype() EffectLifeTime = Property.Float(0) DieDelay = Property.Float(0) def Initialize(self, initializer): self.activated = False def Destroy(self): if not self.activated: self.activated = True created = self.Space.CreateAtPosition(self.Archetype, self.Owner.Transform.Translation) if self.EffectLifeTime > 0: self.AddDestroyAction(created, self.EffectLifeTime) if self.DieDelay > 0: self.AddDestroyAction(self.Owner, self.DieDelay) else: self.Owner.Destroy() def AddDestroyAction(self, target, countdown): def Destroy(self): self.Owner.Destroy() if not target.ActionList: target.AddComponentByName("ActionList") target.ActionList.EmptyAll() target.ActionList.AddCallback(Destroy, has_self=True, blocking=False, countdown=countdown)
class Hookable: Active = Property.Bool(False) NonActivatable = Property.Bool(False) def Initialize(self, initializer): if self.NonActivatable: self.Active = False def Hook(self, target): if self.Owner.TimedDeath: self.Owner.TimedDeath.Active = False if self.Active: if self.Owner.Teleportable: self.Owner.Teleportable.Active = False self.Owner.AttachToRelative(target) self.Owner.RigidBody.Static = True if not self.Owner.CanCollect: self.Owner.AddComponentByName("CanCollect") def UnHook(self): self.Owner.RigidBody.Static = False self.Owner.DetachRelative() if self.Owner.Teleportable: self.Owner.Teleportable.Active = True if self.Owner.TimedDeath: self.Owner.TimedDeath.Active = True if self.Owner.CanCollect: self.Owner.RemoveComponentByName("CanCollect")
class Event_TitleLevel: Camera = Property.Cog() Player = Property.Cog() CurrentFunction = None E1ToE2Delay = 2 def Initialize(self, initializer): self.Space.SoundSpace.PlayMusic("Cave") self.Player.PlayerController.Active = False Zero.Connect(self.Space, Events.LevelStarted, self.OnLevelStart) Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) def OnLogicUpdate(self, UpdateEvent): if self.CurrentFunction == None: return self.CurrentFunction() def OnLevelStart(self, LevelStartEvent): self.Camera.CameraFunction.SetCameraFade(Vec4(0, 0, 0, 1), Vec4(0, 0, 0, 0), 0.01, 0) self.CurrentFunction = self.E1_ActivateLogo self.Player.PlayerController.Active = True def E1_ActivateLogo(self): if self.Camera.CameraFunction.FadeDone: self.CurrentFunction = None
class HotfixTeleporter: ActivateWhenTargetDestroy = Property.Cog() NextLevel = Property.Level() def Initialize(self, initializer): self.teleporting = False if self.ActivateWhenTargetDestroy: self.ActivateWhenTargetDestroy.DestroyInterface.RegisterObserver( self.Teleport) def Teleport(self): if not self.teleporting: if self.NextLevel.Name != "DefaultLevel": self.Space.FindObjectByName( "Camera").CameraFunction.SetCameraFade( Vec4(1, 1, 1, 0), Vec4(1, 1, 1, 1), .03, 0) ls = self.Space.FindObjectByName("LevelSettings").LevelStart if ls: ls.HUDManager.HideBoxes() hm = ls.HUDManager hm.CacheSkills() sequence = Action.Sequence(self.Owner.Actions) Action.Delay(sequence, 1.5) Action.Call(sequence, lambda: self.Space.LoadLevel(self.NextLevel)) self.teleporting = True
class RandomYeller: Xrange = Property.Float(5) Yrange = Property.Float(5) #Active = Property.Bool(False) def Initialize(self, initializer): self.random_string = [ "What are you doing!?", "Stop it!", "Don't do that!", "No! No!", "No!", "Stop!!", "What!?", "No, Stop!!", "Stop!! Stop!!", "It hurts!!", "What have you done?!", "STOP!", "NO!!" ] pass def CreateOne(self): #if self.Active: x = self.Owner.Transform.WorldTranslation.x + (random.random() - 0.5) * self.Xrange * 2 y = self.Owner.Transform.WorldTranslation.y + (random.random() - 0.5) * self.Yrange * 2 yt = self.Space.CreateAtPosition("YellingTemplate", VectorMath.Vec3(x, y, 1)) yt.TypeScript.String = self.random_string[random.randint( 0, len(self.random_string) - 1)]
class CanBounce: Active = Property.Bool(True) ForcedVx = Property.Float(0) ForcedVy = Property.Float(0) UpdateBasedOnSprite = Property.Bool(False) def Initialize(self, initializer): self.InitialStrength = math.sqrt(self.ForcedVx**2 + self.ForcedVy**2) Zero.Connect(self.Owner, Events.CollisionStarted, self.OnCollision) def OnCollision(self, CollisionEvent): if self.Active: if self.UpdateBasedOnSprite: if (self.Owner.Sprite.FlipX == True and self.ForcedVx > 0) or (self.Owner.Sprite.FlipX == False and self.ForcedVx < 0): self.ForcedVx = -self.ForcedVx if CollisionEvent.OtherObject.Bounceable: impulseEvent = Zero.ScriptEvent() impulseEvent.ForcedVx = self.ForcedVx impulseEvent.ForcedVy = self.ForcedVy CollisionEvent.OtherObject.DispatchEvent( "BounceEvent", impulseEvent) def ToDirection(self, normal): self.ForcedVx = self.InitialStrength * normal.x self.ForcedVy = self.InitialStrength * normal.y
class Projectile: #Logic for projectile from weapon #Varaibles Speed = Property.Float(1.0) Direction = Vec3(0, 0, 0) timedDestruction = Property.Float(3.5) def Initialize(self, initializer): #creating update and collision events Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) Zero.Connect(self.Owner, Events.CollisionStarted, self.OnCollisionStart) #setting variables self.existanceTimer = 0 def OnLogicUpdate(self, UpdateEvent): #Moving logic self.Owner.Transform.Translation += self.Direction * UpdateEvent.Dt * self.Speed #increase timer self.existanceTimer += UpdateEvent.Dt * 10 #destroy after a certain time if (self.existanceTimer > self.timedDestruction): self.Owner.Destroy() def OnCollisionStart(self, CollisionEvent): #if the projectile collides with anything except the player, keys, gold, or gates it is destroyed otherObject = CollisionEvent.OtherObject if (otherObject.Name != "Player" and otherObject.Name != "Key" and otherObject.Name != "AOE" and otherObject.Name != "Gold" and otherObject.Name != "GateAOE" and otherObject.Name != "SwitchGateAOE"): self.Owner.Destroy()
def Cloth_Rigger_AddColliderMeshes_OnClicked(): prop = PPG.Inspected(0) Property.AddObjectToList(prop, 'ColliderMeshes', 'Pick Collider Mesh') Property.AddColliderObject(prop) Cloth_Rigger_RebuildLayout(prop) PPG.Refresh()
class PlayerController: JumpStrength = Property.Float(2.0) MoveForce = Property.Float(3.0) JumpActive = Property.Bool(True) Active = Property.Bool(True) def Initialize(self, initializer): self.Space.SoundSpace.PlayCue("RainCue") Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) def OnLogicUpdate(self, UpdateEvent): if (not self.Active): return self.Owner.Sprite.AnimationSpeed = abs(self.Owner.RigidBody.Velocity.x) force = Vec3(0, 0, 0) impulse = Vec3(0, 0, 0) if Zero.Keyboard.KeyIsDown(Zero.Keys.D): self.Owner.Sprite.FlipX = False force += Vec3(1, 0, 0) if Zero.Keyboard.KeyIsDown(Zero.Keys.A): self.Owner.Sprite.FlipX = True force -= Vec3(1, 0, 0) if Zero.Keyboard.KeyIsDown(Zero.Keys.W): impulse += Vec3(0, 1, 0) self.Owner.RigidBody.ApplyLinearVelocity(force * self.MoveForce) self.Owner.RigidBody.ApplyLinearVelocity(impulse * self.JumpStrength)
class CanSpawnWind: Active = Property.Bool(True) Size = Property.Float(1) Force = Property.Float(1) def Initialize(self, initializer): self.windregion = self.Space.CreateAtPosition( "WindRegion", self.Owner.Transform.WorldTranslation) self.windregion.Transform.Scale *= VectorMath.Vec3(1, self.Size, 1) self.windregion.CanBlow.BlowForce *= self.Force Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) def OnLogicUpdate(self, UpdateEvent): if self.Active: if not self.windregion: self.windregion = self.Space.CreateAtPosition( "WindRegion", self.Owner.Transform.WorldTranslation) if self.Owner: self.windregion.Transform.WorldTranslation = self.Owner.Transform.WorldTranslation else: if self.windregion: self.windregion.Destroy() def Destroyed(self): if self.windregion: self.windregion.Destroy()
class KeyHoleDoor: KeyHole = Property.String("") DoorTable = Property.ResourceTable() NextLevel = Property.Level() Teleport = Property.Cog() SimpleTeleport = Property.Bool(False) def Initialize(self, initializer): Zero.Connect(self.Owner, Events.CollisionStarted, self.OnCollision) self.TryKeyEvent = Zero.ScriptEvent() self.TryKeyEvent.Callback = lambda: self.OpenDoor() self.TryKeyEvent.KeyHole = self.KeyHole self.Opened = True if not self.KeyHole else False self.observer_list = [] def OnCollision(self, CollisionEvent): CollisionEvent.OtherObject.DispatchEvent("TryKeyEvent", self.TryKeyEvent) def TeleportThis(self, target): if self.NextLevel.Name != "DefaultLevel": self.Space.FindObjectByName("Camera").CameraFunction.SetCameraFade( Vec4(1, 1, 1, 0), Vec4(1, 1, 1, 1), .03, 0) sequence = Action.Sequence(self.Owner.Actions) ls = self.Space.FindObjectByName("LevelSettings").LevelStart if ls: hm = ls.HUDManager hm.CacheSkills() Action.Delay(sequence, 1.5) Action.Call(sequence, lambda: self.Space.LoadLevel(self.NextLevel)) elif self.Teleport: camera = self.Space.FindObjectByName("Camera") dest = self.Teleport.Transform.Translation ct = camera.Transform.Translation pt = target.Transform.Translation #camera.CameraFunction.SetCameraFade(Vec4(0,0,0,1),Vec4(0,0,0,0),.03,0) #camera.Transform.Translation = VectorMath.Vec3(dest.x, dest.y,ct.z) target.Transform.Translation = VectorMath.Vec3( dest.x, dest.y, pt.z) def RegisterObserver(self, observer): self.observer_list.append(observer) def OpenDoor(self): self.Owner.Sprite.SpriteSource = self.DoorTable.FindResource("Black") self.Opened = True for callback in self.observer_list: callback() self.observer_list = [] def IsOpened(self): return self.Opened
class BurnAnim: Active = Property.Bool(True) Alpha = Property.Float(0.26) def Initialize(self, initializer): self.burnanim = None Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) def OnLogicUpdate(self, UpdateEvent): if not self.Active: if self.burnanim: self.burnanim.Destroy() else: if not self.burnanim: self.burnanim = self.Space.CreateAtPosition( "FireParticle", self.Owner.Transform.Translation) t = self.burnanim.SpriteParticleSystem.Tint t.a = self.Alpha self.burnanim.SpriteParticleSystem.Tint = t self.burnanim.Transform.Scale = self.Owner.Transform.Scale self.burnanim.AttachToRelative(self.Owner) def Destroyed(self): if self.burnanim: self.burnanim.Destroy()
class Bounceable: Decay = Property.Float(1) Active = Property.Bool(True) def Initialize(self, initializer): Zero.Connect(self.Owner, "BounceEvent", self.OnBounce) def OnBounce(self, BounceEvent): if self.Active: if self.Owner.PlayerController: self.Owner.PlayerController.TriggerBounced() Vx = BounceEvent.ForcedVx Vy = BounceEvent.ForcedVy self_v = self.Owner.RigidBody.Velocity self_v.x = self_v.x if Vx == 0 else Vx self_v.y = self_v.y if Vy == 0 else Vy self.Owner.RigidBody.Velocity = self_v * self.Decay if self.Owner.PlayerController and abs(Vx) > (Vy) * .9: self.Owner.PlayerController.LockHorizontal() seq = Action.Sequence(self.Owner.Actions) Action.Delay(seq, .35) Action.Call(seq, self.Owner.PlayerController.UnlockHorizontal) print("event received", self.Owner.Name, Vx, Vy, self.Owner.RigidBody.Velocity)
class AIMovementPacing: Duration = Property.Float(1.0) Speed = Property.Float(1.0) Direction = Property.Int(+1) Active = Property.Bool(+1) SpeedMultiplier = Property.Float(1.0) def Initialize(self, initializer): self.accum_dt = 0 self.init_direction = self.Direction self.resetcounter = 0 Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) def OnLogicUpdate(self, UpdateEvent): if self.Active: if self.resetcounter > 0: self.resetcounter -= 1 else: self.SpeedMultiplier = 1 self.Owner.Sprite.FlipX = self.Direction > 0 self.Owner.Transform.Translation += Vec3(self.Direction,0,0) * self.Speed * self.SpeedMultiplier self.accum_dt += UpdateEvent.Dt * self.Direction * self.init_direction if self.accum_dt > self.Duration: self.Direction = -1 elif self.accum_dt < 0: self.Direction = +1 def SlowDownBy(self, SlowDownRatio, TimeSteps): self.resetcounter = TimeSteps self.SpeedMultiplier = SlowDownRatio
class TimedDeath: LifeTime = Property.Float(1.0) Active = Property.Bool(False) DestroyAtTheEnd = Property.Bool(False) def Initialize(self, initializer): self.Callback = None Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) def Activate(self, callback=0): self.Active = True if callback != 0: self.SetCallBack(callback) def SetCallback(self, callback): self.Callback = callback def OnLogicUpdate(self, UpdateEvent): if not self.Active: pass else: self.LifeTime -= UpdateEvent.Dt if self.LifeTime <= 0: if self.Callback: self.Callback(self) if self.DestroyAtTheEnd: self.Owner.Destroy()
def Cloth_Rigger_RemoveColliderMeshes_OnClicked(): prop = PPG.Inspected(0) Property.RemoveColliderObject(prop) Property.RemoveObjectFromList(PPG.Inspected(0), 'ColliderMeshes') Cloth_Rigger_RebuildLayout(PPG.Inspected(0)) PPG.Refresh()
class PlayerController: JumpStrength = Property.Float(2.0) MoveForce = Property.Float(3.0) JumpActive = Property.Bool(True) Active = Property.Bool(True) def Initialize(self, initializer): Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) def OnLogicUpdate(self, UpdateEvent): if (not self.Active): return force = Vec3(0, 0, 0) impulse = Vec3(0, 0, 0) if Zero.Keyboard.KeyIsDown(Zero.Keys.D): force += Vec3(1, 0, 0) if Zero.Keyboard.KeyIsDown(Zero.Keys.A): force -= Vec3(1, 0, 0) if Zero.Keyboard.KeyIsDown(Zero.Keys.W): impulse += Vec3(0, 1, 0) if Zero.Keyboard.KeyIsDown(Zero.Keys.S): impulse += Vec3(0, -1, 0) self.Owner.RigidBody.ApplyLinearVelocity(force * self.MoveForce) self.Owner.RigidBody.ApplyLinearVelocity(impulse * self.JumpStrength)
class CanTeleport: Active = Property.Bool(True) SpriteDependentOffset = Property.Bool(False) Offset = Property.Float(3.5) def Initialize(self, initializer): pass def Teleport(self, target): if self.Active: canberooted = self.Owner.FindRoot().CanBeRooted if canberooted: if not self.SpriteDependentOffset: target.Transform.Translation += canberooted.GetNormal() * self.Offset else: for child in self.Owner.Parent.Hierarchy.Children: if child.Name == "surfroot": break target.Transform.WorldTranslation = child.Transform.WorldTranslation + canberooted.GetNormal()*.1 + Vec3(0,0.2,0) if target.RigidBody: target.RigidBody.ApplyLinearVelocity(canberooted.GetNormal()*10) if not target.RigidBody.RotationLocked: target.RigidBody.ApplyAngularVelocity(Vec3(0,0,10)) else: target.Transform.Translation += Vec3(0,self.Offset,0)
class HealthStatus: MaxHealth = Property.Float(100.0) RegenRate = Property.Float(0) Updatable = Property.Bool(True) UseVisualCue = Property.Bool(False) def Initialize(self, initializer): self.health = self.MaxHealth self.isdead = False self.init_regen = self.RegenRate if self.UseVisualCue: self.healthparticle = self.Space.CreateAtPosition( "HealthParticle", self.Owner.Transform.WorldTranslation) self.healthparticle.AttachToRelative(self.Owner) self.healthparticle.SphericalParticleEmitter.Active = False Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) def AddHealth(self, health): if self.Updatable: if not self.isdead: self.health += health if health < 0 and self.UseVisualCue: self.healthparticle.SphericalParticleEmitter.Active = True self.healthparticle.SphericalParticleEmitter.ResetCount() if self.health > self.MaxHealth: self.health = self.MaxHealth elif self.health < 0: self.isdead = True if self.Owner.CanFancyDie: self.Owner.CanFancyDie.Die() self.health = 0 def GetHealth(self): return self.health def IsDead(self): return self.isdead def ResetRegen(self): self.RegenRate = self.init_regen def RegenHealth(self, regen_rate): self.RegenRate = regen_rate def ResetHealth(self): self.health = self.MaxHealth self.isdead = False def Reset(self): self.ResetHealth() self.ResetRegen() def OnLogicUpdate(self, UpdateEvent): if self.RegenRate != 0 and self.Updatable: self.AddHealth(UpdateEvent.Dt * self.RegenRate)
def DefineProperties(self): self.Start = Property.Bool(True) self.FireY = Property.Float(0) self.Speed = Property.Float(200) self.HasCollided = Property.Bool(False)
class AIMovementSentry: Speed = Property.Float(1.0) InitialDirection = Property.Vector3(Vec3(1, 0, 0)) Active = Property.Bool(True) RandomStop = Property.Bool(True) RandomFlip = Property.Bool(True) def Initialize(self, initializer): self.Direction = self.InitialDirection self.resetcounter = 0 self.SpeedMultiplier = 1 self.target_multiplier = 1 self.stopcounter = 0 if not self.Owner.AIMovementInterface: self.Owner.AddComponentByName("AIMovementInterface") self.Owner.AIMovementInterface.Set(self) Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) Zero.Connect(self.Owner, Events.CollisionStarted, self.OnCollision) def OnLogicUpdate(self, UpdateEvent): if self.Active: self.resetcounter -= 1 if self.resetcounter == 0: self.SpeedMultiplier = 1 self.stopcounter -= 1 self.SpeedMultiplier = self.SpeedMultiplier * .99 + 1 * self.target_multiplier * 0.01 self.Owner.Sprite.FlipX = self.Direction.x < 0 self.Owner.Transform.Translation += self.Direction * self.Speed * self.SpeedMultiplier if self.RandomStop and self.stopcounter <= 0: self.stopcounter = random.random() * 200 self.target_multiplier = random.random() * 2 if self.RandomFlip and random.random() < 0.0001: self.Direction *= -1 def OnCollision(self, CollisionEvent): if CollisionEvent.OtherObject.IsSentry: if abs(CollisionEvent.FirstPoint.WorldNormalTowardsOther.x) > 0.95: direction = CollisionEvent.OtherObject.IsSentry.SentryDirection if direction.x == 0 and direction.y == 0: self.Direction = Vec3( 1, 0, 0 ) if CollisionEvent.FirstPoint.WorldNormalTowardsOther.x < 0 else Vec3( -1, 0, 0) else: self.Direction = direction def SlowDownBy(self, SlowDownRatio, TimeSteps): self.resetcounter = TimeSteps self.SpeedMultiplier = SlowDownRatio
class FadeAnim: FadingDuration = Property.Float(1) Active = Property.Bool(True) FadeDirection = Property.Int(-1) Repeat = Property.Bool(False) def Initialize(self, initializer): Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) self.target = self.Owner.Sprite or self.Owner.SpriteText self.targetslist = tuple(item for item in (self.Owner.Sprite, self.Owner.SpriteText) if item) def ApplyAlpha(self, target, alpha): tc = target.Color target.Color = Vec4(tc.x, tc.y, tc.z, alpha) def CheckAlphaBound(self, alpha): # if alpha out of bounds if alpha < 0: alpha = 0 if not self.Repeat: self.Active = False else: self.FadeDirection = 1 elif alpha > 1: alpha = 1 if not self.Repeat: self.Active = False else: self.FadeDirection = -1 return alpha def OnLogicUpdate(self, UpdateEvent): if self.Active: # calculate new alpha c = self.target.Color alpha = c.a + self.FadeDirection * (1. / self.FadingDuration) * UpdateEvent.Dt alpha = self.CheckAlphaBound(alpha) for target in self.targetslist: self.ApplyAlpha(target, alpha) def Off(self): self.Active = False def On(self): self.Active = True def Toggle(self): self.Active = not self.Active def ResetAlpha(self, alpha=1): for target in self.targetslist: self.ApplyAlpha(target, 1)
class GotLight: Light = Property.Cog() Size = Property.Float(.25) def Initialize(self, initializer): self.Light = self.Space.CreateAtPosition("LightCircle", self.Owner.Transform.Translation) self.Light.AttachToRelative(self.Owner) self.Light.SphereCollider.Radius = self.Size def ChangeSize(self, size): self.Size = size self.Light.SphereCollider.Radius = self.Size
class CreateSpawnerAtInit: Teleporter = Property.Cog() Delay = Property.Float(5) def Initialize(self, initializer): self.Teleporter = self.Space.CreateAtPosition( "EnemySpawner", self.Owner.Transform.Translation) if not self.Owner.DestroyTeleport: self.Owner.AddComponentByName("DestroyTeleport") self.Teleporter.MonsterSpawner.RespawnDelay = self.Delay
class Blowable: Active = Property.Bool(True) Decay = Property.Float(1.0) def Initialize(self, initializer): Zero.Connect(self.Owner, Events.CollisionPersisted, self.OnCollision) def OnCollision(self, CollisionEvent): if self.Active and CollisionEvent.OtherObject.CanBlow: CollisionEvent.OtherObject.CanBlow.Blow(self.Owner, self.Decay)
class AbilitySoulBehavior: MoveSpeed = Property.Float(10) ReleaseToExplodeTime = Property.Float(0.05) NoMoving = Property.Bool(False) def Initialize(self, initializer): Zero.Connect(self.Space, Events.LogicUpdate, self.OnLogicUpdate) self.CurrentUpdate = self.InitialState self.InitialPosition = self.Owner.Transform.Translation self.TrackingTarget = self.Space.FindObjectByName("Player") self.Timer = 0 def OnLogicUpdate(self, UpdateEvent): if self.CurrentUpdate: self.CurrentUpdate(UpdateEvent) def InitialState(self, UpdateEvent): self.Owner.RigidBody.ApplyLinearVelocity(Vec3(0, self.MoveSpeed, 0)) self.Timer += UpdateEvent.Dt if self.Timer > self.ReleaseToExplodeTime: self.Owner.RigidBody.Velocity = Vec3(0, 0, 0) self.CurrentUpdate = self.ExplodeState def ExplodeState(self, UpdateEvent): #self.Owner.SphericalParticleEmitter.Size -= UpdateEvent.Dt * 10 #if self.Owner.SphericalParticleEmitter.Size <= 1: self.CurrentUpdate = None sequence = Action.Sequence(self.Owner) Action.Delay(sequence, 0.5) def SetState(): self.CurrentUpdate = self.EndState Action.Call(sequence, SetState) def EndState(self, UpdateEvent): pos = self.Owner.Transform.Translation pos.z = 0 if not self.NoMoving: self.Owner.Transform.Translation = pos * 0.9 + self.TrackingTarget.Transform.Translation * 0.1 self.Owner.SphericalParticleEmitter.Size *= 0.9 if self.Owner.SphericalParticleEmitter.Size < 0.1 and self.Owner.CanTransferAbility.IsActivated( ): souls = tuple( self.Space.CreateAtPosition( "SoulEffect", self.TrackingTarget.Transform.Translation) for _ in range(20)) for item in souls: item.SphericalParticleEmitter.Size = 0.3 item.SoulBehavior.WillDecay = True item.SpriteParticleSystem.Tint = self.Owner.SpriteParticleSystem.Tint self.Owner.Destroy()
class CanBlow: BlowDirection = Property.Vector3(VectorMath.Vec3(0, 1, 0)) BlowForce = Property.Float(4) def Initialize(self, initializer): pass def Blow(self, target, decay): if target.RigidBody: target.RigidBody.ApplyForce(self.BlowDirection * self.BlowForce * decay)
def DefineProperties(self): self.GlobalZ = Property.Float(0) self.timer = Property.Float() self.Delay = Property.Float(3) self.start = Property.Bool(True) self.RandomAngle = Property.Float(0) self.CanAnimate = Property.Bool(True) self.CanAnimateIdle = Property.Bool(False) self.CanAnimateIdle2 = Property.Bool(False) self.CanShoot = Property.Bool(False) self.CanIdle = Property.Bool(False)
def UpdateStatuses(availabilityLag): db = Database() sql = u"select id from property where usable = 1 and removed = 0 and let_agreed = 0 and availability_lag <= {0};" sql = sql.format(availabilityLag); pendingLetAgreed = db.runSqlQueryColumn(sql) for propertyId in pendingLetAgreed: property = Property(db, propertyId) property.updateStatus()
def GetAdditionalMetadata(availabilityLag): db = Database() sql = u"select id from property where usable = 1 and removed = 0 and availability_lag <= {0} and num_photos is null;" sql = sql.format(availabilityLag); properties = db.runSqlQueryColumn(sql) for propertyId in properties: property = Property(db, propertyId) property.getAdditionalMetadata()
class KeySpriteManager: SpriteTable = Property.ResourceTable() ShineDelay = Property.Float(1.7) def Initialize(self, initializer): self.shinesprite = self.SpriteTable.FindValue(self.Owner.Key.KeyValue + "Shine") self.seq = Action.Sequence(self.Owner.Actions) self.PlayShineAnim() def PlayShineAnim(self): self.Owner.Sprite.SpriteSource = self.shinesprite Action.Delay(self.seq, self.ShineDelay) Action.Call(self.seq, self.PlayShineAnim)
def UpdateStatuses(availabilityLag): db = Database() sql = u"select id from property where usable = 1 and let_agreed = 0 and removed = 0 and availability_lag <= {0};" sql = sql.format(availabilityLag) pendingLetAgreed = db.runSqlQueryColumn(sql) for propertyId in pendingLetAgreed: property = Property(db, propertyId) property.checkLetAgreed()
def RunSentimentAnalysis(): hiv4 = ps.HIV4() db = Database() sql = u"select id from property;" propertyIds = db.runSqlQueryColumn(sql) for propertyId in propertyIds: property = Property(db, propertyId) property.analyseSentiment(hiv4)
def CleanupText(): db = Database() sql = u"select id from property;" propertyIds = db.runSqlQueryColumn(sql) # Portions of code copied from: # Latent Dirichlet Allocation (LDA) with Python # by Jordan Barber nltk.download("stopwords") nltk.download("wordnet") tokenizer = RegexpTokenizer(r'\w+') stemmer = PorterStemmer() stopWords = stopwords.words('english') for propertyId in propertyIds: property = Property(db, propertyId) property.cleanupText(tokenizer, stopWords, stemmer)