home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / pocimac.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2000-10-27  |  20.6 KB  |  487 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import OnInitTake
  5. import ReadGSFile
  6. import Bladex
  7. import Actions
  8. import CharStats
  9. import whrandom
  10. import GenFX
  11. import Reference
  12. import AuxFuncs
  13. POTION_STATE_USED = 0
  14. POTION_STATE_UNUSED = 1
  15. POTION_TYPE_EAT = 0
  16. POTION_TYPE_DRINK_RIGHT = 1
  17. POTION_TYPE_GULP = 2
  18. POTION_TYPE_DRINK_LEFT = 3
  19. POWERUP_TYPE_LIFE = 0
  20. POWERUP_TYPE_ATTACK = 1
  21. POWERUP_DEACTIVATED = 2
  22. POWERUP_ACTIVATED = 1
  23.  
  24. def RestoreWounds(EntityName, woundfactor = 0.0):
  25.     me = Bladex.GetEntity(EntityName)
  26.     woundlist = []
  27.     for i in range(32):
  28.         pass
  29.     
  30.     while len(woundlist) and len(woundlist) / 11.0 > woundfactor:
  31.         if woundlist.count(3):
  32.             wound2clear = 3
  33.         elif whrandom.randint(0, 1):
  34.             wound2clear = whrandom.choice(woundlist)
  35.         else:
  36.             wound2clear = woundlist[0]
  37.         me.SetWoundedZone(wound2clear, 0)
  38.         woundlist.remove(wound2clear)
  39.  
  40.  
  41. def RestoreWoundsToLifeLevel(EntityName):
  42.     me = Bladex.GetEntity(EntityName)
  43.     woundfactor = 1.0 - me.Life / CharStats.GetCharMaxLife(me.Kind, me.Level)
  44.     RestoreWounds(EntityName, woundfactor)
  45.  
  46.  
  47. class Pocima:
  48.     
  49.     def __init__(self, pot):
  50.         self.Hand = 0
  51.         self.Estado = POTION_STATE_UNUSED
  52.         self.Increment = 25
  53.         self.MaxLife = 200
  54.         self.DrinkFunc = 0
  55.         self.DrinkFuncArguments = ()
  56.         self.Sonido = 0
  57.         self.Type = POTION_TYPE_DRINK_RIGHT
  58.         self.OHand = ''
  59.         self.PowerPotion = 0
  60.         self.TimeStartPowerPotion = 5.0
  61.         self.TimePowerPotion = 10.0
  62.         self.OldFDefense = 0.0
  63.         self.OldFAttack = 0.0
  64.         self.FDefense = 4.0
  65.         self.FAttack = 4.0
  66.         self.PowerUpEstado = POWERUP_DEACTIVATED
  67.         self.LifePowerUpI = 0
  68.         self.LifePowerUp = 100
  69.         self.FadeDelta = 0.2 / 60.0
  70.         self.CuresPoison = 0
  71.  
  72.     
  73.     def IncrementLife(self):
  74.         UsedBy2 = Bladex.GetEntity(self.entity)
  75.         UsedBy = self
  76.         if UsedBy.PowerUpEstado == POWERUP_ACTIVATED:
  77.             if UsedBy.LifePowerUpI < UsedBy.LifePowerUp:
  78.                 life = UsedBy2.Life + 1.0
  79.                 if life <= self.MaxLife:
  80.                     UsedBy.LifePowerUpI = UsedBy.LifePowerUpI + 1.0
  81.                     UsedBy2.Life = life
  82.                     RestoreWoundsToLifeLevel(UsedBy2.Name)
  83.                 
  84.                 timenext = 0.5
  85.                 Bladex.AddScheduledFunc(Bladex.GetTime() + timenext, self.IncrementLife, ())
  86.             else:
  87.                 UsedBy.PowerUpEstado = POTION_STATE_USED
  88.         
  89.  
  90.     
  91.     def ActivatePowerUp(self, sector, entity):
  92.         UsedBy = self
  93.         if UsedBy.PowerUpEstado == POWERUP_DEACTIVATED:
  94.             self.entity = entity
  95.             UsedBy.PowerUpEstado = POWERUP_ACTIVATED
  96.             Bladex.AddScheduledFunc(Bladex.GetTime() + 0.5, self.IncrementLife, ())
  97.         
  98.  
  99.     
  100.     def DeactivatePowerUp(self, sector, entity):
  101.         if entity == self.entity:
  102.             UsedBy = self
  103.             if UsedBy.PowerUpEstado == POWERUP_ACTIVATED:
  104.                 UsedBy.PowerUpEstado = POWERUP_DEACTIVATED
  105.             
  106.         
  107.  
  108.     
  109.     def FinishPowerAtack(self, entity):
  110.         UsedBy = Bladex.GetEntity(entity)
  111.         if UsedBy.Data.PowerPotion == 1:
  112.             UsedBy.SelfIlum = 0.0
  113.             UsedBy.Data.FDefense = self.OldFDefense
  114.             UsedBy.Data.FAttack = self.OldFAttack
  115.             UsedBy.Data.PowerPotion = 2
  116.         
  117.  
  118.     
  119.     def StartPowerAtack(self):
  120.         if self.PowerUpEstado == POWERUP_ACTIVATED:
  121.             UsedBy = Bladex.GetEntity(self.entity)
  122.             UsedBy.SelfIlum = 1.0
  123.             self.OldFDefense = 1.0
  124.             self.OldFAttack = 1.0
  125.             UsedBy.Data.FDefense = self.FDefense
  126.             UsedBy.Data.FAttack = self.FAttack
  127.             UsedBy.Data.PowerPotion = 1
  128.             Bladex.AddScheduledFunc(Bladex.GetTime() + self.TimePowerPotion, self.FinishPowerAtack, (self.entity,))
  129.         
  130.  
  131.     
  132.     def ActivatePowerUpAtack(self, sector, entity):
  133.         if self.PowerUpEstado == POWERUP_DEACTIVATED:
  134.             UsedBy = Bladex.GetEntity(entity)
  135.             if UsedBy.Data.PowerPotion == 0:
  136.                 self.PowerUpEstado = POWERUP_ACTIVATED
  137.                 self.entity = entity
  138.                 Bladex.AddScheduledFunc(Bladex.GetTime() + self.TimeStartPowerPotion, self.StartPowerAtack, ())
  139.             
  140.         
  141.  
  142.     
  143.     def DeactivatePowerUpAtack(self, sector, entity):
  144.         if entity == self.entity:
  145.             self.PowerUpEstado = POWERUP_DEACTIVATED
  146.         
  147.  
  148.     
  149.     def Reset(self, Players = 0):
  150.         pass
  151.  
  152.     
  153.     def FadeOut(self, entity, timer):
  154.         poc = Bladex.GetEntity(entity)
  155.         poc.Alpha = poc.Alpha - poc.Data.FadeDelta
  156.         if len(poc.Lights):
  157.             poc.Lights = [
  158.                 (poc.Alpha / 2, poc.Lights[0][1], poc.Lights[0][2])]
  159.         
  160.         if poc.Alpha <= 0:
  161.             poc.SubscribeToList('Pin')
  162.         
  163.  
  164.  
  165.  
  166. def RestoreHand(entidad):
  167.     char = Bladex.GetEntity(entidad)
  168.     char.AddAnmEventFunc('ChangeREvent', Actions.ToggleWEvent)
  169.     char.LaunchAnmType('Chg_r')
  170.  
  171.  
  172. def TakePotionUsed():
  173.     pass
  174.  
  175.  
  176. def PocimaNoSoltada(entidad):
  177.     Reference.debugprint('PocimaNoSoltada')
  178.     char = Bladex.GetEntity(entidad)
  179.     object = Bladex.GetEntity(char.Data.obj_used)
  180.     if object.Data.Estado == POTION_STATE_USED:
  181.         SoltarPocima(entidad, 0)
  182.     else:
  183.         object.ExcludeHitFor(char)
  184.         inv = char.GetInventory()
  185.         if object.Data.Type == POTION_TYPE_DRINK_LEFT:
  186.             inv.LinkLeftHand2('None')
  187.             impulse = char.Rel2AbsVector(1000.0 * object.Mass, -1000.0 * object.Mass, 0.0)
  188.             object.Impulse(impulse[0], impulse[1], impulse[2])
  189.         else:
  190.             inv.LinkRightHand('None')
  191.             if object.Data.Hand == 1:
  192.                 char.AnmEndedFunc = RestoreHand
  193.             
  194.             inv.RemoveObject(char.Data.obj_used)
  195.             impulse = char.Rel2AbsVector(-1000.0 * object.Mass, -1000.0 * object.Mass, 0.0)
  196.             object.Impulse(impulse[0], impulse[1], impulse[2])
  197.  
  198.  
  199. def SoltarFood(Entidad):
  200.     char = Bladex.GetEntity(Entidad)
  201.     char.AnmEndedFunc = ''
  202.     inv = char.GetInventory()
  203.     inv.LinkRightHand('None')
  204.     inv.RemoveObject(char.Data.obj_used)
  205.     Actions.TakeStraightRecover(Entidad)
  206.  
  207.  
  208. def SoltarPocima(Entidad, Evento = 0):
  209.     char = Bladex.GetEntity(Entidad)
  210.     char.AnmEndedFunc = ''
  211.     if Evento:
  212.         char.DelAnmEventFunc(Evento)
  213.     
  214.     object = Bladex.GetEntity(char.Data.obj_used)
  215.     object.ExcludeHitFor(char)
  216.     object.TimerFunc = object.Data.FadeOut
  217.     object.SubscribeToList('Timer60')
  218.     inv = char.GetInventory()
  219.     if object.Data.Type == POTION_TYPE_DRINK_LEFT:
  220.         inv.LinkLeftHand2('None')
  221.         inv.RemoveObject(char.Data.obj_used)
  222.         impulse = char.Rel2AbsVector(1000.0 * object.Mass, -1000.0 * object.Mass, 0.0)
  223.         object.Impulse(impulse[0], impulse[1], impulse[2])
  224.     else:
  225.         inv.LinkRightHand('None')
  226.         if object.Data.Hand == 1:
  227.             char.AnmEndedFunc = RestoreHand
  228.         else:
  229.             char.AnmEndedFunc = Actions.TakeStraightRecover
  230.         inv.RemoveObject(char.Data.obj_used)
  231.         impulse = char.Rel2AbsVector(-1000.0 * object.Mass, -1000.0 * object.Mass, 0.0)
  232.         object.Impulse(impulse[0], impulse[1], impulse[2])
  233.     OnInitTake.AddOnInitTakeEvent(object.Name, TakePotionUsed)
  234.  
  235.  
  236. def RestorePowerPotion(Entidad, Potion):
  237.     char = Bladex.GetEntity(Entidad)
  238.     char.Data.FDefense = Potion.OldFDefense
  239.     char.Data.FAttack = Potion.OldFAttack
  240.     char.Data.PowerPotion = 0
  241.  
  242.  
  243. def BeberPocima(Entidad, Evento):
  244.     char = Bladex.GetEntity(Entidad)
  245.     char.DelAnmEventFunc(Evento)
  246.     Poti = Bladex.GetEntity(char.Data.obj_used)
  247.     Pot = Poti.Data
  248.     Pot.Estado = POTION_STATE_USED
  249.     if Pot.PowerPotion:
  250.         Pot.OldFDefense = char.Data.FDefense
  251.         Pot.OldFAttack = char.Data.FAttack
  252.         char.Data.FDefense = Pot.FDefense
  253.         char.Data.FAttack = Pot.FAttack
  254.         char.Data.PowerPotion = 1
  255.         Bladex.AddScheduledFunc(Bladex.GetTime() + Pot.TimePowerPotion, RestorePowerPotion, (Entidad, Pot))
  256.         GenFX.AddPersonItemFX(Entidad, Poti.Name, Pot.TimePowerPotion)
  257.     elif Poti.Kind == 'PocimaTodo':
  258.         char.Life = CharStats.GetCharMaxLife(char.Kind, char.Level)
  259.         RestoreWounds(Entidad)
  260.     else:
  261.         Life = char.Life + Pot.Increment
  262.         LimitLife = CharStats.GetCharMaxLife(char.Kind, char.Level)
  263.         if Life > LimitLife:
  264.             char.Life = LimitLife
  265.         else:
  266.             char.Life = Life
  267.         RestoreWoundsToLifeLevel(Entidad)
  268.     if Pot.CuresPoison:
  269.         char.Data.UnVenom()
  270.     
  271.     Pot.Sonido.Play(char.Position[0], char.Position[1], char.Position[2], 0)
  272.     if Pot.DrinkFunc != 0:
  273.         Bladex.AddScheduledFunc(Bladex.GetTime(), Pot.DrinkFunc, Pot.DrinkFuncArguments)
  274.     
  275.  
  276.  
  277. def CreateMiguillas(Entidad, Evento):
  278.     char = Bladex.GetEntity(Entidad)
  279.     Poti = Bladex.GetEntity(char.Data.obj_used)
  280.     miguillas = Bladex.CreateEntity('Miguillas', 'Entity Particle System D1', 0, 0, 0)
  281.     miguillas.ParticleType = 'Miguillas'
  282.     miguillas.YGravity = 10000.0
  283.     miguillas.Friction = 0.2
  284.     miguillas.RandomVelocity = 10.0
  285.     miguillas.PPS = 200
  286.     miguillas.Time2Live = 32
  287.     miguillas.DeathTime = Bladex.GetTime() + 0.1
  288.     Poti.Link(miguillas)
  289.     if Evento == 'Bocado1Event':
  290.         Poti.TimerFunc = Poti.Data.FadeOut
  291.         Poti.SubscribeToList('Timer60')
  292.     
  293.  
  294.  
  295. def UsePotion3(Entity):
  296.     char = Bladex.GetEntity(Entity)
  297.     UsePotion2(char.Data.obj_used)
  298.  
  299.  
  300. def UsePotion2(NombrePocima):
  301.     Reference.debugprint('UsePotion2')
  302.     Pocima = Bladex.GetEntity(NombrePocima)
  303.     Char = Bladex.GetEntity(Pocima.Data.UsedBy)
  304.     Reference.debugprint(Char.AnmEndedFunc)
  305.     Char.AnmEndedFunc = Actions.TakeStraightRecover
  306.     if Pocima.Data.Type == POTION_TYPE_EAT:
  307.         Char.LaunchAnmType('eat00')
  308.         Char.AddAnmEventFunc('Bocado1Event', CreateMiguillas)
  309.         Char.AddAnmEventFunc('Bocado2Event', CreateMiguillas)
  310.         Char.AnmEndedFunc = SoltarFood
  311.     elif Pocima.Data.Type == POTION_TYPE_DRINK_RIGHT:
  312.         Char.LaunchAnmType('drink')
  313.         Char.AddAnmEventFunc('PickBottle', PickPotion)
  314.     elif Pocima.Data.Type == POTION_TYPE_GULP:
  315.         Char.LaunchAnmType('gulp00')
  316.     else:
  317.         print 'Unknown Potion Type' + `Pocima.Data.Type`
  318.     Char.AddAnmEventFunc('drinkingEvent', BeberPocima)
  319.     print 'should throw bottle with event ThrowBottle in animation ' + Char.AnimName
  320.     Char.AddAnmEventFunc('ThrowBottle', SoltarPocima)
  321.  
  322.  
  323. def UsePotion(NombrePocima, TipoUso):
  324.     Pocima = Bladex.GetEntity(NombrePocima)
  325.     Pocima.Data.Hand = 0
  326.     Char = Bladex.GetEntity(Pocima.Data.UsedBy)
  327.     Char.Data.obj_used = NombrePocima
  328.     Char.AnmEndedFunc = PocimaNoSoltada
  329.     if TipoUso == Actions.USE_FROM_INV and Pocima.Data.Estado == POTION_STATE_UNUSED:
  330.         Pocima.Data.Type = 1
  331.         if not (Char.InvRight):
  332.             UsePotion2(NombrePocima)
  333.         elif Char.InCombat:
  334.             if not (Char.InvLeft2):
  335.                 Pocima.Data.Type = 3
  336.                 Char.LaunchAnmType('attack_drink')
  337.                 Char.AddAnmEventFunc('PickBottle', PickPotion)
  338.                 Char.AddAnmEventFunc('drinkingEvent', BeberPocima)
  339.                 Char.AddAnmEventFunc('ThrowBottle', SoltarPocima)
  340.             
  341.         elif Actions.IsRightHandStandardObject(Char.Name):
  342.             if Actions.TryDropRight(Char.Name):
  343.                 Actions.DropReleaseEventHandler(Char.Name, 'DropRightEvent')
  344.             
  345.             if not (Char.InvRight):
  346.                 UsePotion2(NombrePocima)
  347.             
  348.         else:
  349.             Char.AddAnmEventFunc('ChangeREvent', Actions.ToggleWEvent)
  350.             Char.LaunchAnmType('Chg_r')
  351.             Pocima.Data.Hand = 1
  352.             Pocima.Data.OHand = Char.InvRight
  353.             Char.AnmEndedFunc = UsePotion3
  354.     elif TipoUso == Actions.USE_FROM_TAKE and Pocima.Data.Estado == POTION_STATE_UNUSED:
  355.         if Pocima.Data.Type != POTION_TYPE_EAT:
  356.             Pocima.Data.Type = POTION_TYPE_GULP
  357.             Char.AnmEndedFunc = UsePotion3
  358.         else:
  359.             Char.AnmEndedFunc = UsePotion3
  360.     
  361.  
  362.  
  363. def PickPotion(Entidad, Evento):
  364.     char = Bladex.GetEntity(Entidad)
  365.     char.DelAnmEventFunc(Evento)
  366.     Pocima = char.Data.obj_used
  367.     object = Bladex.GetEntity(char.Data.obj_used)
  368.     inv = char.GetInventory()
  369.     if object.Data.Type == 3:
  370.         inv.LinkLeftHand2(Pocima)
  371.     else:
  372.         inv.LinkRightHand(Pocima)
  373.  
  374.  
  375. def CreatePotion(Nombre, Increment = 25, MaxLife = 180):
  376.     Pot = Bladex.GetEntity(Nombre)
  377.     Pot.Static = 0
  378.     Pot.Data = Pocima(Pot)
  379.     Pot.UseFunc = UsePotion
  380.     Pot.Data.Increment = Increment
  381.     Pot.Data.MaxLife = MaxLife
  382.     kind = Pot.Kind
  383.     if kind == 'Pocima25':
  384.         Pot.Data.Increment = 25
  385.     elif kind == 'Pocima50':
  386.         Pot.Data.Increment = 50
  387.     elif kind == 'Pocima100':
  388.         Pot.Data.Increment = 100
  389.     elif kind == 'Pocima200':
  390.         Pot.Data.Increment = 200
  391.     
  392.     Pot.Data.CuresPoison = 1
  393.     Pot.Data.Sonido = Bladex.CreateSound('..\\..\\Sounds\\Drink.wav', 'Drinking')
  394.     Pot.Data.Sonido.Volume = 1
  395.     Pot.Data.Sonido.MinDistance = 10000
  396.     Pot.Data.Sonido.MaxDistance = 20000
  397.     return Pot.Data
  398.  
  399.  
  400. def CreateFood(Nombre, Increment = 25, MaxLife = 180):
  401.     Pot = Bladex.GetEntity(Nombre)
  402.     Pot.Static = 0
  403.     Pot.Data = Pocima(Pot)
  404.     Pot.UseFunc = UsePotion
  405.     Pot.Data.Increment = Increment
  406.     Pot.Data.MaxLife = MaxLife
  407.     Pot.Data.Type = POTION_TYPE_EAT
  408.     Pot.Data.Sonido = Bladex.CreateSound('..\\..\\Sounds\\bugbite-bone2.wav', 'Eating')
  409.     Pot.Data.Sonido.Volume = 1
  410.     Pot.Data.Sonido.MinDistance = 10000
  411.     Pot.Data.Sonido.MaxDistance = 20000
  412.     Pot.Data.FadeDelta = 0.8 / 60.0
  413.     kind = Pot.Kind
  414.     if kind == 'Queso':
  415.         Pot.Data.Increment = 10
  416.     elif kind == 'Paletilla':
  417.         Pot.Data.Increment = 10
  418.     elif kind == 'Manzana':
  419.         Pot.Data.Increment = 5
  420.     elif kind == 'Setas':
  421.         Pot.Data.Increment = 5
  422.     elif kind == 'Seta':
  423.         Pot.Data.Increment = 5
  424.     elif kind == 'Rabano':
  425.         Pot.Data.Increment = 5
  426.         Pot.Data.CuresPoison = 1
  427.     elif kind == 'Raiz':
  428.         Pot.Data.Increment = 5
  429.     elif kind == 'Saquito':
  430.         Pot.Data.Increment = 5
  431.     elif kind == 'Hogaza':
  432.         Pot.Data.Increment = 10
  433.     
  434.     return Pot.Data
  435.  
  436.  
  437. def CreatePowerPotion(Nombre, FD = 4.0, FA = 4.0, Time = 10):
  438.     PowerPot = CreatePotion(Nombre)
  439.     PowerPot.TimePowerPotion = Time
  440.     PowerPot.PowerPotion = 1
  441.     PowerPot.FDefense = FD
  442.     PowerPot.FAttack = FA
  443.     PowerPot.Increment = 0
  444.     PowerPot.CuresPoison = 0
  445.     pp = Bladex.GetEntity(Nombre)
  446.     pp.FiresIntensity = [
  447.         45]
  448.     pp.Lights = [
  449.         (0.5, 0.05, (0, 128, 255))]
  450.     pp.SelfIlum = 1
  451.     spot = AuxFuncs.GetSpot(pp)
  452.     if spot:
  453.         spot.Visible = 0
  454.         spot.CastShadows = 0
  455.     
  456.  
  457.  
  458. def CreatePowerUp(Sector, Name, Life = 100, MaxLife = 100):
  459.     res = ReadGSFile.ReadGhostSectorFile(Sector)
  460.     for igs in res:
  461.         Bladex.AddTriggerSector(igs['Name'], igs['Grupo'], igs['FloorHeight'], igs['RoofHeight'], igs['Vertex'])
  462.     
  463.     PowerUp = Pocima(0)
  464.     Bladex.SetTriggerSectorFunc(Name, 'OnLeave', PowerUp.DeactivatePowerUp)
  465.     Bladex.SetTriggerSectorFunc(Name, 'OnEnter', PowerUp.ActivatePowerUp)
  466.     PowerUp.Type = POWERUP_TYPE_LIFE
  467.     PowerUp.LifePowerUp = Life
  468.     PowerUp.MaxLife = MaxLife
  469.     return PowerUp
  470.  
  471.  
  472. def CreatePowerUpAtack(Sector, Name, FD = 4.0, FA = 4.0, TimeD = 10, TimeL = 5):
  473.     res = ReadGSFile.ReadGhostSectorFile(Sector)
  474.     for igs in res:
  475.         Bladex.AddTriggerSector(igs['Name'], igs['Grupo'], igs['FloorHeight'], igs['RoofHeight'], igs['Vertex'])
  476.     
  477.     PowerUp = Pocima(0)
  478.     Bladex.SetTriggerSectorFunc(Name, 'OnLeave', PowerUp.DeactivatePowerUpAtack)
  479.     Bladex.SetTriggerSectorFunc(Name, 'OnEnter', PowerUp.ActivatePowerUpAtack)
  480.     PowerUp.Type = POWERUP_TYPE_ATTACK
  481.     PowerUp.TimeStartPowerPotion = TimeL
  482.     PowerUp.TimePowerPotion = TimeD
  483.     PowerUp.FDefense = FD
  484.     PowerUp.FAttack = FA
  485.     return PowerUp
  486.  
  487.