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

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 1.5)
  3.  
  4. import Bladex
  5. import Ontake
  6. import Stars
  7. import string
  8. import math
  9. import Reference
  10. import Breakings
  11. import InitDataField
  12. import OnInitTake
  13. import AuxFuncs
  14. import B3DLib
  15. import netgame
  16. import Damage
  17. import CharStats
  18. import MenuText
  19. import Netval
  20. import Torchs
  21. import ItemTypes
  22. START_FADEOUT_IN_BIG_FALL = 2.0
  23. END_FADEOUT_IN_BIG_FALL = 2.5
  24. if Reference.DEBUG_INFO == 1:
  25.     import pdb
  26.  
  27. import pdb
  28. TRUE = 1 == 1
  29. FALSE = 1 != 1
  30. RA_NO_WEAPON = 0
  31. RA_1H_WEAPON = 1
  32. RA_BOW = 2
  33. RA_2H_OBJECT = 3
  34. RA_TORCH = 4
  35. LA_NO_WEAPON = 0
  36. LA_SHIELD = 1
  37. LA_BOW = 2
  38. LA_2H_OBJECT = 2
  39. PI = math.pi
  40. TWOPI = PI * 2
  41. FACINGANGLE = PI * 0.125
  42. BEHINDANGLE = PI * 0.75
  43. B_SOLID_MASK_PERSON = 1
  44. B_SOLID_MASK_FLOOR = 2
  45. B_SOLID_MASK_CAMERA = 4
  46. B_SOLID_MASK_PARTICLES = 8
  47. MESSAGE_START_WEAPON = 7
  48. MESSAGE_STOP_WEAPON = 8
  49. MESSAGE_START_TRAIL = 14
  50. MESSAGE_STOP_TRAIL = 15
  51. InterpWithOff = (0,)
  52. InterpWithOutOff = (1,)
  53. InertialIntrp = (2,)
  54. FixedRFootIntep = (3,)
  55. FixedLFootIntep = (4,)
  56. FixedFootAutoInterp = 5
  57.  
  58. def ReportMsg(Msg):
  59.     if netgame.GetNetState() == 0:
  60.         import GameText
  61.         GameText.WriteTextAux(MenuText.GetMenuText(Msg), 2.0, 255, 255, 255, [])
  62.     
  63.  
  64.  
  65. def GetListOfObjectsAt(inv, id):
  66.     if inv.GetNumberObjectsAt(id) == 1:
  67.         name = inv.GetObject(id)
  68.         if name:
  69.             return [
  70.                 name]
  71.         else:
  72.             return []
  73.     else:
  74.         corray = range(inv.GetNumberObjectsAt(id))
  75.     resulto = []
  76.     for i in corray:
  77.         name = inv.GetObject(id)
  78.         inv.RemoveObject(name)
  79.         ExtendedTakeObject(inv, name)
  80.         resulto.append(name)
  81.     
  82.     return resulto
  83.  
  84.  
  85. def RemoveAllKeys(EntityName):
  86.     me = Bladex.GetEntity(EntityName)
  87.     inv = me.GetInventory()
  88.     keyNames = []
  89.     for j in range(inv.nKeys):
  90.         keyNames.append(inv.GetKey(j))
  91.     
  92.     for key in keyNames:
  93.         inv.RemoveKey(key)
  94.     
  95.  
  96.  
  97. def RemoveNoTravelObjects(EntityName):
  98.     me = Bladex.GetEntity(EntityName)
  99.     inv = me.GetInventory()
  100.     objname = inv.GetObject(0)
  101.     counterid = 0
  102.     while objname:
  103.         obj = Bladex.GetEntity(objname)
  104.         if obj.Kind in Reference.TravelObjects:
  105.             counterid = counterid + 1
  106.         else:
  107.             inv.RemoveObject(objname)
  108.         objname = inv.GetObject(counterid)
  109.  
  110.  
  111. def PutAllInBack(EntityName):
  112.     me = Bladex.GetEntity(EntityName)
  113.     right = me.InvRight
  114.     left = me.InvLeft
  115.     rightback = me.InvRightBack
  116.     leftback = me.InvLeftBack
  117.     inv = me.GetInventory()
  118.     inv.LinkRightHand('')
  119.     inv.LinkLeftHand('')
  120.     inv.LinkBack('')
  121.     if leftback:
  122.         inv.LinkLeftBack(leftback)
  123.     elif not leftback and left:
  124.         inv.LinkLeftBack(left)
  125.     elif leftback and left:
  126.         print 'ERROR - Actions.PutAllInBack -> leftback and left both diff on none!!!'
  127.         inv.LinkLeftBack(leftback)
  128.         print '   Linked only the back one...'
  129.     
  130.     if rightback:
  131.         inv.LinkRightBack(rightback)
  132.     elif not rightback and right:
  133.         inv.LinkRightBack(right)
  134.     elif rightback and right:
  135.         print 'ERROR - Actions.PutAllInBack -> rightback and right both diff on none!!!'
  136.         inv.LinkRightBack(rightback)
  137.         print '   Linked only the back one...'
  138.     
  139.  
  140.  
  141. def Start_Weapon(EntityName, EventName):
  142.     me = Bladex.GetEntity(EntityName)
  143.     if me:
  144.         inv = me.GetInventory()
  145.         if inv:
  146.             weapon_name = inv.GetActiveWeapon()
  147.             if weapon_name:
  148.                 weapon = Bladex.GetEntity(weapon_name)
  149.                 if weapon:
  150.                     weapon.MessageEvent(Reference.MESSAGE_START_WEAPON, 0, 0)
  151.                 
  152.             
  153.         
  154.     
  155.  
  156.  
  157. def Stop_Weapon(EntityName, EventName):
  158.     me = Bladex.GetEntity(EntityName)
  159.     if me:
  160.         inv = me.GetInventory()
  161.         if inv:
  162.             weapon_name = inv.GetActiveWeapon()
  163.             if weapon_name:
  164.                 weapon = Bladex.GetEntity(weapon_name)
  165.                 if weapon:
  166.                     weapon.MessageEvent(Reference.MESSAGE_STOP_WEAPON, 0, 0)
  167.                 
  168.             
  169.         
  170.     
  171.  
  172.  
  173. def Start_Trail(EntityName, EventName):
  174.     me = Bladex.GetEntity(EntityName)
  175.     if me:
  176.         inv = me.GetInventory()
  177.         if inv:
  178.             weapon_name = inv.GetActiveWeapon()
  179.             if weapon_name:
  180.                 weapon = Bladex.GetEntity(weapon_name)
  181.                 if weapon:
  182.                     weapon.MessageEvent(Reference.MESSAGE_START_TRAIL, 0, 0)
  183.                 
  184.             
  185.         
  186.     
  187.  
  188.  
  189. def Stop_Trail(EntityName, EventName):
  190.     me = Bladex.GetEntity(EntityName)
  191.     if me:
  192.         inv = me.GetInventory()
  193.         if inv:
  194.             weapon_name = inv.GetActiveWeapon()
  195.             if weapon_name:
  196.                 weapon = Bladex.GetEntity(weapon_name)
  197.                 if weapon:
  198.                     weapon.MessageEvent(Reference.MESSAGE_STOP_TRAIL, 0, 0)
  199.                 
  200.             
  201.         
  202.     
  203.  
  204.  
  205. def GraspString(EntityName, EventName):
  206.     me = Bladex.GetEntity(EntityName)
  207.     if me:
  208.         inv = me.GetInventory()
  209.         if inv:
  210.             if inv.HoldingBow:
  211.                 bow = Bladex.GetEntity(inv.GetBow())
  212.                 
  213.                 try:
  214.                     bow.Data.GraspString()
  215.                 except AttributeError:
  216.                     print "No string on bow. Do ItemTypes.ItemDefaultFuncs(Bladex.GetEntity('" + bow.Name + "'))"
  217.  
  218.             
  219.         
  220.     
  221.  
  222.  
  223. def UnGraspString(EntityName, EventName):
  224.     me = Bladex.GetEntity(EntityName)
  225.     if me:
  226.         inv = me.GetInventory()
  227.         if inv:
  228.             if inv.HoldingBow:
  229.                 bow = Bladex.GetEntity(inv.GetBow())
  230.                 
  231.                 try:
  232.                     bow.Data.UnGraspString()
  233.                 except AttributeError:
  234.                     print "No string on bow. Do ItemTypes.ItemDefaultFuncs(Bladex.GetEntity('" + bow.Name + "'))"
  235.  
  236.             
  237.         
  238.     
  239.  
  240.  
  241. def AddQuiver(inv, new_quiver_name):
  242.     new_quiver = Bladex.GetEntity(new_quiver_name)
  243.     for i in range(inv.nQuivers):
  244.         quiver_name = inv.GetQuiver(i)
  245.         quiver = Bladex.GetEntity(quiver_name)
  246.         if quiver.Data.ArrowType == new_quiver.Data.ArrowType:
  247.             inv.SetCurrentQuiver(quiver_name)
  248.             quiver.Data.ReceiveArrows(new_quiver.Data.NumberOfArrows(), inv.Owner)
  249.             new_quiver.SubscribeToList('Pin')
  250.             inv.LinkRightHand('None')
  251.             return None
  252.         
  253.     
  254.     inv.AddQuiver(new_quiver_name)
  255.     inv.SetCurrentQuiver(new_quiver_name)
  256.     inv.LinkRightHand('None')
  257.     if inv.HoldingBow:
  258.         inv.LinkBack(new_quiver_name)
  259.     
  260.  
  261.  
  262. def ExtendedTakeObject(inv, Object2TakeName):
  263.     o = Bladex.GetEntity(Object2TakeName)
  264.     if o.Kind in Reference.StackObjects.keys():
  265.         inv.AddObject(Object2TakeName, Reference.StackObjects[o.Kind] - 1)
  266.     else:
  267.         inv.AddObject(Object2TakeName, 0)
  268.  
  269.  
  270. def TakeObject(EntityName, Object2TakeName, force_take = TRUE):
  271.     me = Bladex.GetEntity(EntityName)
  272.     inv = me.GetInventory()
  273.     if IsOneTooMany(EntityName, Object2TakeName):
  274.         if force_take:
  275.             DropToMakeRoomFor(EntityName, Object2TakeName)
  276.         else:
  277.             print EntityName + ': Too many objects of this type: ' + Object2TakeName
  278.             return None
  279.     
  280.     object_flag = Reference.GiveObjectFlag(Object2TakeName)
  281.     
  282.     try:
  283.         me.Data.RegisterObjectAsTaken(Object2TakeName)
  284.     except:
  285.         if EntityName == 'Player1':
  286.             print Object2TakeName + ' not registered as taken, Players Data class not created yet'
  287.         
  288.  
  289.     if object_flag == Reference.OBJ_ITEM:
  290.         ExtendedTakeObject(inv, Object2TakeName)
  291.     elif object_flag == Reference.OBJ_SHIELD:
  292.         inv.AddShield(Object2TakeName)
  293.         if not (me.InvLeftBack) and not (me.InvRightBack) and not (me.InvLeft):
  294.             inv.LinkLeftHand(Object2TakeName)
  295.         
  296.     elif object_flag == Reference.OBJ_WEAPON:
  297.         flag = Reference.GiveWeaponFlag(Object2TakeName)
  298.         inv.AddWeapon(Object2TakeName, flag)
  299.         if me.InvLeftBack == '' and me.InvRightBack == '' and me.InvRight == '':
  300.             inv.LinkRightHand(Object2TakeName)
  301.         
  302.     elif object_flag == Reference.OBJ_BOW:
  303.         inv.AddBow(Object2TakeName)
  304.         if not (me.InvLeftBack) and not (me.InvRightBack) and not (me.InvRight) and not (me.InvLeft):
  305.             inv.LinkLeftHand(Object2TakeName)
  306.         
  307.     elif object_flag == Reference.OBJ_QUIVER:
  308.         AddQuiver(inv, Object2TakeName)
  309.     elif object_flag == Reference.OBJ_STANDARD:
  310.         if not (me.InvLeftBack) and not (me.InvRightBack) and not (me.InvRight):
  311.             inv.LinkRightHand(Object2TakeName)
  312.         
  313.     elif object_flag == Reference.OBJ_KEY:
  314.         inv.AddKey(Object2TakeName)
  315.     elif object_flag == Reference.OBJ_SPECIALKEY:
  316.         inv.AddSpecialKey(Object2TakeName)
  317.     elif object_flag == Reference.OBJ_TABLET:
  318.         inv.AddTablet(Object2TakeName)
  319.     elif object_flag == Reference.OBJ_ARROW:
  320.         pass
  321.     elif object_flag == Reference.OBJ_USEME and EntityName != 'Player1':
  322.         ExtendedTakeObject(inv, Object2TakeName)
  323.     else:
  324.         print 'ERROR adding an object to a character !!!'
  325.         print 'Not classified properly in Reference.py!!!'
  326.  
  327.  
  328. def StatR(EntityName):
  329.     me = Bladex.GetEntity(EntityName)
  330.     ObjectName = me.InvRight
  331.     if ObjectName == 'None' or not ObjectName:
  332.         return RA_NO_WEAPON
  333.     
  334.     object_flag = Reference.GiveObjectFlag(ObjectName)
  335.     if object_flag == Reference.OBJ_BOW:
  336.         return RA_BOW
  337.     else:
  338.         return RA_1H_WEAPON
  339.  
  340.  
  341. def StatL(EntityName):
  342.     me = Bladex.GetEntity(EntityName)
  343.     ObjectName = me.InvLeft
  344.     if ObjectName == 'None' or not ObjectName:
  345.         return LA_NO_WEAPON
  346.     
  347.     object_flag = Reference.GiveObjectFlag(ObjectName)
  348.     if object_flag == Reference.OBJ_SHIELD:
  349.         return LA_SHIELD
  350.     elif object_flag == Reference.OBJ_BOW:
  351.         return LA_BOW
  352.     else:
  353.         print 'ERROR - Invalid object in left hand!!!'
  354.         print 'Check it in Reference.py!!!'
  355.         return None
  356.  
  357.  
  358. def IsRightHandStandardObject(EntityName):
  359.     me = Bladex.GetEntity(EntityName)
  360.     if not (me.InvRight):
  361.         return FALSE
  362.     
  363.     object_flag = Reference.GiveObjectFlag(me.InvRight)
  364.     return object_flag == Reference.OBJ_STANDARD
  365.  
  366.  
  367. def IsRightHandWeaponObject(EntityName):
  368.     me = Bladex.GetEntity(EntityName)
  369.     if not (me.InvRight):
  370.         return FALSE
  371.     
  372.     object_flag = Reference.GiveObjectFlag(me.InvRight)
  373.     if not object_flag == Reference.OBJ_WEAPON:
  374.         pass
  375.     return object_flag == Reference.OBJ_BOW
  376.  
  377.  
  378. def IsRightHandAutomaticObject(EntityName):
  379.     me = Bladex.GetEntity(EntityName)
  380.     if not (me.InvRight):
  381.         return FALSE
  382.     
  383.     object_flag = Reference.GiveObjectFlag(me.InvRight)
  384.     return object_flag == Reference.OBJ_USEME
  385.  
  386.  
  387. def IsBehindEntity(MyName, OtherName):
  388.     them = Bladex.GetEntity(OtherName)
  389.     angle1 = them.Angle
  390.     angle2 = B3DLib.GetEntity2EntityAngle(OtherName, MyName)
  391.     return abs(B3DLib.DiffAngle(angle1, angle2)) >= BEHINDANGLE
  392.  
  393.  
  394. def IsFacingEntity(MyName, OtherName):
  395.     me = Bladex.GetEntity(MyName)
  396.     angle1 = me.Angle
  397.     angle2 = B3DLib.GetEntity2EntityAngle(MyName, OtherName)
  398.     return abs(B3DLib.DiffAngle(angle1, angle2)) <= FACINGANGLE
  399.  
  400.  
  401. def IsFacingPos(MyName, x, z):
  402.     me = Bladex.GetEntity(MyName)
  403.     angle1 = me.Angle
  404.     p1 = me.Position
  405.     x = x - p1[0]
  406.     z = z - p1[2]
  407.     angle2 = B3DLib.GetXZAngle(x, 0.0, z)
  408.     return abs(B3DLib.DiffAngle(angle1, angle2)) <= FACINGANGLE
  409.  
  410.  
  411. def Turn180(MyName):
  412.     me = Bladex.GetEntity(MyName)
  413.     angle = me.Angle + PI
  414.     if angle >= TWOPI:
  415.         angle = angle - TWOPI
  416.     
  417.     me.Face(angle)
  418.  
  419.  
  420. def QuickTurn180(MyName):
  421.     me = Bladex.GetEntity(MyName)
  422.     angle = me.Angle + PI
  423.     if angle >= TWOPI:
  424.         angle = angle - TWOPI
  425.     
  426.     me.QuickFace(angle)
  427.  
  428.  
  429. def TurnToFaceEntity(MyName, OtherName):
  430.     me = Bladex.GetEntity(MyName)
  431.     angle = B3DLib.GetEntity2EntityAngle(MyName, OtherName)
  432.     me.Face(angle)
  433.  
  434.  
  435. def TurnToFaceEntityNow(MyName, OtherName):
  436.     me = Bladex.GetEntity(MyName)
  437.     angle = B3DLib.GetEntity2EntityAngle(MyName, OtherName)
  438.     me.Angle = angle
  439.  
  440.  
  441. def QuickTurnToFaceEntity(MyName, OtherName):
  442.     me = Bladex.GetEntity(MyName)
  443.     angle = B3DLib.GetEntity2EntityAngle(MyName, OtherName)
  444.     me.QuickFace(angle)
  445.  
  446.  
  447. def TurnToFacePos(MyName, x, z):
  448.     me = Bladex.GetEntity(MyName)
  449.     p1 = me.Position
  450.     x = x - p1[0]
  451.     z = z - p1[2]
  452.     angle = B3DLib.GetXZAngle(x, 0.0, z)
  453.     me.Face(angle)
  454.  
  455.  
  456. def QuickTurnToFacePos(MyName, x, z):
  457.     me = Bladex.GetEntity(MyName)
  458.     p1 = me.Position
  459.     x = x - p1[0]
  460.     z = z - p1[2]
  461.     angle = B3DLib.GetXZAngle(x, 0.0, z)
  462.     me.QuickFace(angle)
  463.  
  464. USE_FROM_INV = 0
  465. USE_FROM_NEARBY = 2
  466. USE_FROM_TAKE = 4
  467.  
  468. def StdUse(EntityName):
  469.     me = Bladex.GetEntity(EntityName)
  470.     if me.Wuea == Reference.WUEA_ENDED:
  471.         return FALSE
  472.     
  473.     if me.Wuea == Reference.WUEA_WAIT:
  474.         return FALSE
  475.     
  476.     if me.AnmEndedFunc:
  477.         return FALSE
  478.     
  479.     TryWithAnother = 1
  480.     if me.Name[0:6] == 'Player' and me.Data.InventoryActive:
  481.         inv = me.GetInventory()
  482.         object_name = inv.GetSelectedObject()
  483.         if object_name:
  484.             object = Bladex.GetEntity(object_name)
  485.             if object and object.CanUse:
  486.                 me.Data.obj_used = object
  487.                 InitDataField.Initialise(object)
  488.                 object.Data.UsedBy = EntityName
  489.                 object.UseFunc(object_name, USE_FROM_INV)
  490.                 TryWithAnother = 0
  491.             
  492.         
  493.     
  494.     if TryWithAnother:
  495.         if me.Data and me.Data.selected_entity:
  496.             if IsValidForUsing(me.Data.selected_entity[0], EntityName):
  497.                 object_flag = Reference.GiveObjectFlag(me.Data.selected_entity[0])
  498.                 if object_flag != Reference.OBJ_USEME and object_flag != Reference.OBJ_ITEM:
  499.                     object = Bladex.GetEntity(me.Data.selected_entity[0])
  500.                     me.Data.obj_used = object
  501.                     InitDataField.Initialise(object)
  502.                     object.Data.UsedBy = EntityName
  503.                     object.UseFunc(object.Name, USE_FROM_NEARBY)
  504.                     return None
  505.                 
  506.             
  507.             if IsValidForTaking(me.Data.selected_entity[0]):
  508.                 me.Data.toggle4t_clearback = FALSE
  509.                 me.Data.stuff_onback_b4 = SthOnBack(EntityName)
  510.                 if TryToTake(EntityName, me.Data.selected_entity[0]):
  511.                     return None
  512.                 
  513.             else:
  514.                 ReportMsg('The selected object cannot be taken')
  515.         else:
  516.             ReportMsg('Nothing selected')
  517.     
  518.  
  519.  
  520. def IsValidForUsing(instance_name, EntityName):
  521.     me = Bladex.GetEntity(EntityName)
  522.     object = Bladex.GetEntity(instance_name)
  523.     if not me and not object and not (object.CanUse) or not (object.UseFunc):
  524.         return FALSE
  525.     
  526.     dist = B3DLib.GetXZDistance(EntityName, instance_name)
  527.     chartype = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  528.     if dist > chartype.Reach * 1.5:
  529.         return FALSE
  530.     
  531.     heightdiff = -(object.Position[1] - (me.Position[1] + me.Dist2Floor))
  532.     if heightdiff < chartype.MinTake:
  533.         return FALSE
  534.     
  535.     if heightdiff > chartype.MaxTake5:
  536.         return FALSE
  537.     
  538.     return TRUE
  539.  
  540.  
  541. def has_torch(EntityName):
  542.     me = Bladex.GetEntity(EntityName)
  543.     obj_name = me.InvRight
  544.     if obj_name:
  545.         obj = Bladex.GetEntity(obj_name)
  546.         if obj:
  547.             return obj.Kind == 'Antorcha'
  548.         
  549.     
  550.     return 0
  551.  
  552.  
  553. def DestroyBurningItem(EntityName, DestroyTime):
  554.     obj = Bladex.GetEntity(EntityName)
  555.     if obj:
  556.         
  557.         try:
  558.             if not (obj.Data.brkobjdata):
  559.                 Breakings.SetBreakable(EntityName, DestroyTime, DestroyTime)
  560.         except:
  561.             Breakings.SetBreakable(EntityName, DestroyTime, DestroyTime)
  562.  
  563.         brkobj = obj.Data.brkobjdata
  564.         Breakings.ExplodeSpecialObject(EntityName, 3500.0)
  565.     
  566.     for n in brkobj.n_piezas:
  567.         brkobj.pieza[n].CatchOnFire(0.0, 0.0, 0.0)
  568.     
  569.  
  570.  
  571. def StdSetFireToUseFunc(ObjectName, use_from):
  572.     object = Bladex.GetEntity(ObjectName)
  573.     object.UseFunc = 0
  574.     from_pos = (0.0, 0.0, 0.0)
  575.     if use_from == USE_FROM_INV and use_from == USE_FROM_NEARBY or use_from == USE_FROM_TAKE:
  576.         EntityName = object.Data.UsedBy
  577.         me = Bladex.GetEntity(EntityName)
  578.         if me:
  579.             if not has_torch(EntityName):
  580.                 return None
  581.             
  582.             torch = Bladex.GetEntity(me.InvRight)
  583.             if torch.Data.torchobjdata.LightStatus == Torchs.OFF:
  584.                 return None
  585.             
  586.             object.Data.UsedBy = me.InvRight
  587.             QuickTurnToFaceEntity(EntityName, ObjectName)
  588.             heightdiff = -(object.Position[1] - (me.Position[1] + me.Dist2Floor))
  589.             chartype = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  590.             me.AddAnmEventFunc('SetAlightEvent', SetAlightEventHandler)
  591.             if heightdiff <= chartype.MaxTake1:
  592.                 me.LaunchAnmType('fire_g')
  593.             elif heightdiff <= chartype.MaxTake2:
  594.                 me.LaunchAnmType('fire0')
  595.             elif heightdiff <= chartype.MaxTake3:
  596.                 me.LaunchAnmType('fire1')
  597.             elif heightdiff <= chartype.MaxTake4:
  598.                 me.LaunchAnmType('fire2')
  599.             elif heightdiff <= chartype.MaxTake5:
  600.                 me.LaunchAnmType('fire3')
  601.             
  602.         
  603.     
  604.  
  605.  
  606. def SetAlight(ObjectName):
  607.     object = Bladex.GetEntity(ObjectName)
  608.     if object:
  609.         
  610.         try:
  611.             UserName = object.Data.UsedBy
  612.             user = Bladex.GetEntity(UserName)
  613.             user_pos = user.Position
  614.         except:
  615.             user_pos = (0.0, 0.0, 0.0)
  616.  
  617.         object.CatchOnFire(user_pos[0], user_pos[1], user_pos[2])
  618.         if object.Data.BurnTime:
  619.             Bladex.AddScheduledFunc(Bladex.GetTime() + object.Data.BurnTime, DestroyBurningItem, (ObjectName, object.Data.DestroyTime), 'SetAlight' + ObjectName)
  620.         
  621.     
  622.  
  623.  
  624. def SetBurnable(EntityName, BurnTime, DestroyTime):
  625.     object = Bladex.GetEntity(EntityName)
  626.     object.UseFunc = StdSetFireToUseFunc
  627.     InitDataField.Initialise(object)
  628.     object.Data.BurnTime = BurnTime
  629.     object.Data.DestroyTime = DestroyTime
  630.  
  631.  
  632. def SetAlightEventHandler(EntityName, EventName):
  633.     me = Bladex.GetEntity(EntityName)
  634.     me.DelAnmEventFunc(EventName)
  635.     if EventName != 'SetAlightEvent':
  636.         return None
  637.     
  638.     object = me.Data.obj_used
  639.     if object:
  640.         SetAlight(object.Name)
  641.     
  642.  
  643.  
  644. def IsValidForTaking(instance_name):
  645.     object = Bladex.GetEntity(instance_name)
  646.     if object:
  647.         if object.Static and object.Weapon and object.WeaponMode == Reference.ACTIVE_WEAPON_MODE:
  648.             return FALSE
  649.         
  650.         if object.Parent:
  651.             parent = Bladex.GetEntity(object.Parent)
  652.             if parent and parent.Person:
  653.                 return FALSE
  654.             
  655.         
  656.         object_data = None
  657.         if Reference.EntitiesObjectData.has_key(instance_name):
  658.             object_data = Reference.EntitiesObjectData[instance_name]
  659.         elif Reference.DefaultObjectData.has_key(object.Kind):
  660.             object_data = Reference.DefaultObjectData[object.Kind]
  661.         
  662.         if not object_data:
  663.             return FALSE
  664.         
  665.         if object_data[0] == Reference.OBJ_USEME and not (object.CanUse):
  666.             return FALSE
  667.         
  668.     
  669.     return TRUE
  670.  
  671.  
  672. def IsValidForThrowing(object_name):
  673.     object = Bladex.GetEntity(object_name)
  674.     if object:
  675.         if Reference.EntitiesObjectData.has_key(object_name):
  676.             object_data = Reference.EntitiesObjectData[object_name]
  677.         elif Reference.DefaultObjectData.has_key(object.Kind):
  678.             object_data = Reference.DefaultObjectData[object.Kind]
  679.         else:
  680.             return FALSE
  681.         object_flag = object_data[0]
  682.         if object_flag == Reference.OBJ_WEAPON and object_flag == Reference.OBJ_BOW or object_flag == Reference.OBJ_STANDARD:
  683.             return TRUE
  684.         
  685.     
  686.     return FALSE
  687.  
  688.  
  689. def IsValidForDropping(ObjectName):
  690.     if Reference.EntitiesObjectData.has_key(ObjectName):
  691.         object_data = Reference.EntitiesObjectData[ObjectName]
  692.     else:
  693.         object = Bladex.GetEntity(ObjectName)
  694.         if not Reference.DefaultObjectData.has_key(object.Kind):
  695.             return TRUE
  696.         
  697.         object_data = Reference.DefaultObjectData[object.Kind]
  698.     object_flag = object_data[0]
  699.     if object_flag == Reference.OBJ_KEY:
  700.         return FALSE
  701.     elif object_flag == Reference.OBJ_SPECIALKEY:
  702.         return FALSE
  703.     elif object_flag == Reference.OBJ_TABLET:
  704.         return FALSE
  705.     elif object_flag == Reference.OBJ_ITEM:
  706.         return FALSE
  707.     else:
  708.         return TRUE
  709.  
  710.  
  711. def GetCheckSelected(func, Data):
  712.     if Data:
  713.         if Data.selected_entity:
  714.             s = Data.selected_entity[0]
  715.             if func(s):
  716.                 return s
  717.             
  718.         
  719.     
  720.     return None
  721.  
  722.  
  723. def DropToMakeRoomFor(EntityName, ObjectName):
  724.     me = Bladex.GetEntity(EntityName)
  725.     object_flag = Reference.GiveObjectFlag(ObjectName)
  726.     inv = me.GetInventory()
  727.     DropObjectName = None
  728.     if object_flag == Reference.OBJ_ARMOUR:
  729.         print 'Warning DropToMakeRoomFor() unimplimented for Armour...'
  730.     elif object_flag == Reference.OBJ_ITEM:
  731.         ObjectKind = Bladex.GetEntity(ObjectName).Kind
  732.         for i in range(inv.nObjects):
  733.             auxname = inv.GetObject(i)
  734.             if auxname:
  735.                 if Bladex.GetEntity(auxname).Kind == ObjectKind:
  736.                     DropObjectName = auxname
  737.                     break
  738.                 
  739.             else:
  740.                 break
  741.         
  742.     elif object_flag == Reference.OBJ_SHIELD:
  743.         DropObjectName = inv.GetShield(0)
  744.     elif object_flag == Reference.OBJ_WEAPON:
  745.         DropObjectName = inv.GetWeapon(0)
  746.     elif object_flag == Reference.OBJ_BOW:
  747.         if inv.HasBow:
  748.             DropObjectName = inv.GetBow()
  749.         else:
  750.             DropObjectName = inv.GetWeapon(0)
  751.     elif object_flag == Reference.OBJ_QUIVER:
  752.         DropObjectName = inv.GetQuiver(0)
  753.     elif object_flag == Reference.OBJ_STANDARD:
  754.         DropObjectName = me.InvRight
  755.     elif object_flag == Reference.OBJ_KEY:
  756.         print 'Warning DropToMakeRoomFor() unimplimented for Keys...'
  757.     elif object_flag == Reference.OBJ_SPECIALKEY:
  758.         print 'Warning DropToMakeRoomFor() unimplimented for Special Keys...'
  759.     elif object_flag == Reference.OBJ_TABLET:
  760.         print 'Warning DropToMakeRoomFor() unimplimented for Tablets...'
  761.     elif object_flag == Reference.OBJ_USEME:
  762.         DropObjectName = me.InvRight
  763.     elif object_flag == Reference.OBJ_ARROW:
  764.         print 'Warning DropToMakeRoomFor() unimplimented for Arrows...'
  765.     
  766.     if DropObjectName:
  767.         object = Bladex.GetEntity(DropObjectName)
  768.         if object:
  769.             RemoveFromInventory(me, object, 'DropToMakeRoomFor ' + ObjectName)
  770.             object.Position = me.Position
  771.             object.ExcludeHitFor(me)
  772.             if object.TestHit:
  773.                 object.RemoveFromWorld()
  774.             else:
  775.                 object.Alpha = 1.0
  776.                 object.Impulse(0.0, 0.0, 0.0)
  777.         
  778.     
  779.  
  780.  
  781. def IsOneTooMany(EntityName, ObjectName):
  782.     me = Bladex.GetEntity(EntityName)
  783.     if Reference.EntitiesObjectData.has_key(ObjectName):
  784.         object_data = Reference.EntitiesObjectData[ObjectName]
  785.     else:
  786.         object = Bladex.GetEntity(ObjectName)
  787.         object_data = Reference.DefaultObjectData[object.Kind]
  788.     object_flag = object_data[0]
  789.     ret_val = FALSE
  790.     inv = me.GetInventory()
  791.     if object_flag == Reference.OBJ_ITEM:
  792.         ret_val = inv.nObjects >= inv.maxObjects
  793.         if not ret_val:
  794.             ObjectEntity = Bladex.GetEntity(ObjectName)
  795.             for i in range(inv.nObjects):
  796.                 auxname = inv.GetObject(i)
  797.                 if auxname:
  798.                     if Bladex.GetEntity(auxname).Kind == ObjectEntity.Kind:
  799.                         ret_val = inv.GetMaxNumberObjectsAt(i) <= inv.GetNumberObjectsAt(i)
  800.                         break
  801.                     
  802.                 else:
  803.                     break
  804.             
  805.         
  806.     elif object_flag == Reference.OBJ_SHIELD:
  807.         ret_val = inv.nShields >= inv.maxShields
  808.     elif object_flag == Reference.OBJ_WEAPON:
  809.         ret_val = inv.nWeapons >= inv.maxWeapons
  810.     elif object_flag == Reference.OBJ_BOW:
  811.         if not inv.nWeapons >= inv.maxWeapons:
  812.             pass
  813.         ret_val = inv.HasBow
  814.     elif object_flag == Reference.OBJ_QUIVER:
  815.         ret_val = inv.nObjects >= inv.maxObjects
  816.     elif object_flag == Reference.OBJ_STANDARD:
  817.         ret_val = FALSE
  818.     elif object_flag == Reference.OBJ_KEY:
  819.         ret_val = FALSE
  820.     elif object_flag == Reference.OBJ_SPECIALKEY:
  821.         ret_val = FALSE
  822.     elif object_flag == Reference.OBJ_TABLET:
  823.         ret_val = FALSE
  824.     elif object_flag == Reference.OBJ_USEME:
  825.         ret_val = FALSE
  826.     elif object_flag == Reference.OBJ_ARROW:
  827.         ret_val = not CouldSheatheArrow(inv, ObjectName)
  828.     
  829.     return ret_val
  830.  
  831.  
  832. def TryToTake(EntityName, ObjectName):
  833.     me = Bladex.GetEntity(EntityName)
  834.     if me.Wuea == Reference.WUEA_ENDED:
  835.         return FALSE
  836.     
  837.     if me.Wuea == Reference.WUEA_WAIT:
  838.         return FALSE
  839.     
  840.     if me.AnmEndedFunc:
  841.         return FALSE
  842.     
  843.     inv = me.GetInventory()
  844.     if inv.CarringObject(ObjectName):
  845.         return FALSE
  846.     
  847.     object = Bladex.GetEntity(ObjectName)
  848.     dist = B3DLib.GetXZDistance(EntityName, ObjectName)
  849.     chartype = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  850.     if dist > chartype.Reach:
  851.         ReportMsg('Not in reach')
  852.         return FALSE
  853.     
  854.     me.Data.last_heightdiff = -(object.Position[1] - (me.Position[1] + me.Dist2Floor))
  855.     if me.Data.last_heightdiff < chartype.MinTake:
  856.         ReportMsg('Too low to pick up')
  857.         return FALSE
  858.     elif me.Data.last_heightdiff > chartype.MaxTake5:
  859.         ReportMsg('Too high to pick up')
  860.         return FALSE
  861.     elif IsOneTooMany(EntityName, ObjectName):
  862.         ReportMsg('Too many objects of this type')
  863.         return FALSE
  864.     
  865.     QuickTurnToFaceEntity(EntityName, ObjectName)
  866.     me.Data.pickup_entity = ObjectName
  867.     IntermediateTake(EntityName, ObjectName)
  868.     return TRUE
  869.  
  870.  
  871. def UnSheatheArrow(inv):
  872.     des_quiver_name = inv.GetSelectedQuiver()
  873.     inv.LinkRightHand('None')
  874.     if des_quiver_name:
  875.         inv.SetCurrentQuiver(des_quiver_name)
  876.         inv.LinkBack('None')
  877.         inv.LinkBack(des_quiver_name)
  878.         quiver = Bladex.GetEntity(des_quiver_name)
  879.         if quiver and quiver.Data.NumberOfArrows() > 0:
  880.             arrow = quiver.Data.GiveArrow()
  881.             if arrow:
  882.                 inv.LinkRightHand(arrow.Name)
  883.                 return None
  884.             
  885.         
  886.     
  887.     ReportMsg('Out of Arrows')
  888.  
  889.  
  890. def CouldSheatheArrow(inv, ArrowName):
  891.     arrow = Bladex.GetEntity(ArrowName)
  892.     for i in range(inv.nQuivers):
  893.         quiver_name = inv.GetQuiver(i)
  894.         quiver = Bladex.GetEntity(quiver_name)
  895.     
  896.     return TRUE
  897.  
  898.  
  899. def SheatheArrow(inv, ArrowName):
  900.     UnGraspString(inv.Owner, 'UnGraspString')
  901.     arrow = Bladex.GetEntity(ArrowName)
  902.     for i in range(inv.nQuivers):
  903.         quiver_name = inv.GetQuiver(i)
  904.         quiver = Bladex.GetEntity(quiver_name)
  905.     
  906.     new_quiver_type = Reference.GiveQuiverType(arrow.Kind)
  907.     if new_quiver_type:
  908.         new_quiver = Bladex.CreateEntity(new_quiver_type + '_for_' + inv.Owner, new_quiver_type + '_E', 0, 0, 0, 'Physic')
  909.         ItemTypes.ItemDefaultFuncs(new_quiver)
  910.         inv.AddQuiver(new_quiver.Name)
  911.         inv.SetCurrentQuiver(new_quiver.Name)
  912.         if inv.HoldingBow:
  913.             inv.LinkBack(new_quiver.Name)
  914.         
  915.         new_quiver.Data.SetNumberOfArrows(0, inv.Owner)
  916.         if new_quiver.Data.ReceiveArrow(arrow, inv.Owner):
  917.             inv.LinkRightHand('None')
  918.             return None
  919.         
  920.     
  921.     DropReleaseEventHandler(inv.Owner, 'DropRightEvent', FALSE)
  922.  
  923.  
  924. def Toggle4TakingEvent(pj_name, event):
  925.     me = Bladex.GetEntity(pj_name)
  926.     inv = me.GetInventory()
  927.     me.DelAnmEventFunc(event)
  928.     if inv.HoldingBow:
  929.         if me.InvRight:
  930.             if Reference.GiveObjectFlag(me.InvRight) == Reference.OBJ_ARROW:
  931.                 SheatheArrow(inv, me.InvRight)
  932.             
  933.         else:
  934.             UnSheatheArrow(inv)
  935.     elif me.InvRightBack and Reference.GiveObjectFlag(me.InvRightBack) != Reference.OBJ_QUIVER:
  936.         if not (me.Data.stuff_onback_b4) and me.Data.toggle4t_clearback:
  937.             tmpr_back = me.InvRightBack
  938.             inv.LinkBack('None')
  939.             inv.LinkRightHand(tmpr_back)
  940.         else:
  941.             inv.LinkRightHand('None')
  942.     elif me.InvRight and not (me.Data.toggle4t_clearback):
  943.         inv.LinkBack(me.InvRight)
  944.     
  945.     inv.LinkRightHand('None')
  946.     if me.Data.toggle4t_clearback:
  947.         me.Data.toggle4t_clearback = FALSE
  948.         if me.InvLeftBack and Reference.GiveObjectFlag(me.InvLeftBack) == Reference.OBJ_BOW:
  949.             ToggleWEvent(pj_name, event)
  950.         
  951.     
  952.  
  953.  
  954. def ToggleRight4Taking(EntityName):
  955.     me = Bladex.GetEntity(EntityName)
  956.     if IsRightHandStandardObject(EntityName):
  957.         if TryDropRight(EntityName):
  958.             print 'TryDropRight is ok'
  959.             DropReleaseEventHandler(EntityName, 'DropRightEvent')
  960.             if me.InvRight:
  961.                 return FALSE
  962.             
  963.         
  964.         me.Wuea = Reference.WUEA_ENDED
  965.     
  966.     if me.InvRight:
  967.         me.AddAnmEventFunc('ChangeREvent', Toggle4TakingEvent)
  968.         UnGraspString(EntityName, 'UnGraspString')
  969.         me.LaunchAnmType('Chg_r')
  970.     
  971.     return TRUE
  972.  
  973.  
  974. def IntermediateTake(EntityName, ObjectName):
  975.     me = Bladex.GetEntity(EntityName)
  976.     object = Bladex.GetEntity(ObjectName)
  977.     inv = me.GetInventory()
  978.     if inv.CarringObject(ObjectName):
  979.         return None
  980.     
  981.     if inv.HoldingBow:
  982.         UnGraspString(EntityName, 'UnGraspString')
  983.     
  984.     if Reference.EntitiesObjectData.has_key(ObjectName):
  985.         object_data = Reference.EntitiesObjectData[ObjectName]
  986.     else:
  987.         object_data = Reference.DefaultObjectData[object.Kind]
  988.     object_flag = object_data[0]
  989.     if object_flag == Reference.OBJ_ARMOUR:
  990.         if me.CharTypeExt != object_data[1]:
  991.             ReportMsg('Type of armour not for me')
  992.             print 'Info is ' + str(object_data[1])
  993.             return None
  994.         
  995.         if me.Data.armour_level >= object_data[2]:
  996.             ReportMsg('Quality of armour not worthy')
  997.             return None
  998.         
  999.         if FreeBothHands(EntityName, None, (), 0):
  1000.             TakeMainAnm(EntityName)
  1001.         else:
  1002.             me.AnmEndedFunc = TakeMainAnm
  1003.     
  1004.     if object_flag == Reference.OBJ_SHIELD:
  1005.         if me.InvRight:
  1006.             if ToggleRight4Taking(EntityName) == FALSE:
  1007.                 return None
  1008.             
  1009.             me.AnmEndedFunc = TakeMainAnm
  1010.         else:
  1011.             TakeMainAnm(EntityName)
  1012.     elif object_flag == Reference.OBJ_BOW:
  1013.         if me.InvRight:
  1014.             if ToggleRight4Taking(EntityName) == FALSE:
  1015.                 return None
  1016.             
  1017.             me.AnmEndedFunc = TakeMainAnm
  1018.         else:
  1019.             TakeMainAnm(EntityName)
  1020.     elif object_flag == Reference.OBJ_WEAPON:
  1021.         if me.InvRight:
  1022.             if ToggleRight4Taking(EntityName) == FALSE:
  1023.                 return None
  1024.             
  1025.             me.AnmEndedFunc = TakeMainAnm
  1026.         else:
  1027.             w_flag = Reference.GiveWeaponFlag(ObjectName)
  1028.             if me.InvLeft != '' and w_flag != Reference.W_FLAG_1H:
  1029.                 me.AddAnmEventFunc('ChangeLEvent', Left2InvEvent)
  1030.                 me.LaunchAnmType('Chg_l')
  1031.                 me.AnmEndedFunc = TakeMainAnm
  1032.             else:
  1033.                 TakeMainAnm(EntityName)
  1034.     elif object_flag == Reference.OBJ_STANDARD:
  1035.         if inv.HoldingBow:
  1036.             if me.InvRight and Reference.GiveObjectFlag(me.InvRight) == Reference.OBJ_ARROW:
  1037.                 SheatheArrow(inv, me.InvRight)
  1038.             
  1039.             inv.LinkBack(me.InvLeft)
  1040.             inv.LinkLeftHand('None')
  1041.         
  1042.         if me.InvRight:
  1043.             if ToggleRight4Taking(EntityName) == FALSE:
  1044.                 return None
  1045.             
  1046.             me.AnmEndedFunc = TakeMainAnm
  1047.         else:
  1048.             TakeMainAnm(EntityName)
  1049.     elif me.InvRight:
  1050.         if ToggleRight4Taking(EntityName) != FALSE:
  1051.             me.AnmEndedFunc = TakeMainAnm
  1052.         
  1053.     else:
  1054.         TakeMainAnm(EntityName)
  1055.  
  1056.  
  1057. def ToggleAfterTakeObj(EntityName):
  1058.     me = Bladex.GetEntity(EntityName)
  1059.     me.AnmEndedFunc = None
  1060.     inv = me.GetInventory()
  1061.     if IsRightHandStandardObject(EntityName):
  1062.         return None
  1063.     
  1064.     me.Data.toggle4t_clearback = TRUE
  1065.     if me.Data.stuff_onback_b4:
  1066.         if SthOnBack(EntityName):
  1067.             ToggleRight4Taking(EntityName)
  1068.         else:
  1069.             ToggleRight4Taking(EntityName)
  1070.     else:
  1071.         ToggleRight4Taking(EntityName)
  1072.  
  1073.  
  1074. def TakeObject2Inv(EntityName):
  1075.     me = Bladex.GetEntity(EntityName)
  1076.     if not (me.Data) or not (me.Data.pickup_entity):
  1077.         return FALSE
  1078.     
  1079.     object_flag = Reference.GiveObjectFlag(me.Data.pickup_entity)
  1080.     if object_flag == Reference.OBJ_ARROW and me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) == Reference.OBJ_BOW:
  1081.         return FALSE
  1082.     
  1083.     back_flag = SthOnBack(EntityName)
  1084.     if back_flag and object_flag == Reference.OBJ_WEAPON:
  1085.         w_flag = Reference.GiveWeaponFlag(me.Data.pickup_entity)
  1086.         if w_flag != Reference.W_FLAG_1H:
  1087.             back_flag = 0
  1088.         
  1089.     
  1090.     weapon_stay = 0
  1091.     if not (me.Data.stuff_onback_b4) and not back_flag and object_flag == Reference.OBJ_WEAPON:
  1092.         if not (me.InvLeft) or Reference.GiveObjectFlag(me.InvLeft) != Reference.OBJ_BOW:
  1093.             weapon_stay = 1
  1094.         
  1095.     
  1096.     if object_flag != Reference.OBJ_STANDARD and object_flag != Reference.OBJ_USEME and not weapon_stay:
  1097.         return TRUE
  1098.     
  1099.     return FALSE
  1100.  
  1101.  
  1102. def TakeObject2Left(EntityName):
  1103.     me = Bladex.GetEntity(EntityName)
  1104.     if me.Data and not (me.Data.pickup_entity == me.InvRight):
  1105.         if me.InvRight:
  1106.             return FALSE
  1107.         
  1108.     
  1109.     if me.Data and me.Data.pickup_entity:
  1110.         if not (me.InvLeft):
  1111.             object_flag = Reference.GiveObjectFlag(me.Data.pickup_entity)
  1112.             if object_flag == Reference.OBJ_SHIELD:
  1113.                 if TwoHandedWeaponOnBack(EntityName):
  1114.                     return FALSE
  1115.                 
  1116.                 if not (me.InvLeftBack):
  1117.                     return TRUE
  1118.                 
  1119.             
  1120.             if object_flag == Reference.OBJ_BOW:
  1121.                 if not (me.InvLeftBack) and not (me.InvRightBack):
  1122.                     return TRUE
  1123.                 
  1124.             
  1125.         
  1126.     
  1127.     return FALSE
  1128.  
  1129.  
  1130. def RemoveRightHandler(EntityName, EventName):
  1131.     me = Bladex.GetEntity(EntityName)
  1132.     me.DelAnmEventFunc(EventName)
  1133.     inv = me.GetInventory()
  1134.     if me.InvRight and Reference.GiveObjectFlag(me.InvRight) == Reference.OBJ_ARROW:
  1135.         SheatheArrow(inv, me.InvRight)
  1136.     else:
  1137.         object_name = me.InvRight
  1138.         inv.LinkRightHand('None')
  1139.         
  1140.         try:
  1141.             if object_name and me.Data.obj2left:
  1142.                 inv.LinkLeftHand(object_name)
  1143.             
  1144.             me.Data.obj2left = None
  1145.         except AttributeError:
  1146.             pass
  1147.  
  1148.  
  1149.  
  1150. def TakeArmour(EntityName):
  1151.     me = Bladex.GetEntity(EntityName)
  1152.     ObjectName = me.Data.pickup_entity
  1153.     object = Bladex.GetEntity(ObjectName)
  1154.     if Reference.EntitiesObjectData.has_key(ObjectName):
  1155.         object_data = Reference.EntitiesObjectData[ObjectName]
  1156.     else:
  1157.         object_data = Reference.DefaultObjectData[object.Kind]
  1158.     if object_data[0] != Reference.OBJ_ARMOUR:
  1159.         print 'ERROR in Actions.TakeArmour , object is not an armour!!!'
  1160.         return None
  1161.     
  1162.     ct = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  1163.     sound = Bladex.CreateSound('..\\..\\Sounds\\cambio-armadura2.wav', EntityName + 'SoundNewArmour')
  1164.     sound.Volume = 0.6
  1165.     sound.MinDistance = 10000
  1166.     sound.MaxDistance = 20000
  1167.     sound.PlayStereo()
  1168.     right = me.InvRight
  1169.     left = me.InvLeft
  1170.     rightback = me.InvRightBack
  1171.     leftback = me.InvLeftBack
  1172.     inv = me.GetInventory()
  1173.     inv.LinkRightHand('')
  1174.     inv.LinkLeftHand('')
  1175.     inv.LinkBack('')
  1176.     me.Data.UnlinkAll(EntityName, '')
  1177.     me.ResetWounds()
  1178.     if object_data[2] == 0:
  1179.         me.SetMesh(ct.NoArmour)
  1180.     elif object_data[2] == 1:
  1181.         me.SetMesh(ct.LowArmour)
  1182.     elif object_data[2] == 2:
  1183.         me.SetMesh(ct.MedArmour)
  1184.     elif object_data[2] == 3:
  1185.         me.SetMesh(ct.HighArmour)
  1186.     else:
  1187.         print 'ERROR in Actions.TakeArmour , armour level!!!'
  1188.     if rightback:
  1189.         inv.LinkBack(rightback)
  1190.     
  1191.     if leftback:
  1192.         inv.LinkBack(leftback)
  1193.     
  1194.     if right:
  1195.         inv.LinkRightHand(right)
  1196.     
  1197.     if left:
  1198.         inv.LinkLeftHand(left)
  1199.     
  1200.     me.Data.armour_level = object_data[2]
  1201.     me.Data.armour_prot_factor = object_data[3]
  1202.     object.SubscribeToList('Pin')
  1203.     me.AnmEndedFunc(EntityName)
  1204.     return None
  1205.  
  1206.  
  1207. def TakeMainAnm(EntityName):
  1208.     me = Bladex.GetEntity(EntityName)
  1209.     chartype = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  1210.     object_name = me.Data.pickup_entity
  1211.     ret = OnInitTake.OnInitTakeFunc(object_name)
  1212.     if OnInitTake.InitTakeDictionary.has_key(object_name) and not ret:
  1213.         return FALSE
  1214.     
  1215.     if not (me.Data.pickup_entity):
  1216.         return FALSE
  1217.     
  1218.     inv = me.GetInventory()
  1219.     if inv.CarringObject(object_name):
  1220.         return FALSE
  1221.     
  1222.     obj2inv = TakeObject2Inv(EntityName)
  1223.     me.Data.obj2left = TakeObject2Left(EntityName)
  1224.     if Reference.GiveObjectFlag(object_name) == Reference.OBJ_ARMOUR:
  1225.         Bladex.AddScheduledFunc(Bladex.GetTime() + 0.5, AuxFuncs.FadeTo, (0.5, 0.5))
  1226.         Bladex.AddScheduledFunc(Bladex.GetTime() + 1.0, TakeArmour, (EntityName,))
  1227.     elif me.Data.last_heightdiff <= chartype.MaxTake1:
  1228.         if obj2inv:
  1229.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1230.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1231.             me.LaunchAnmType('tke_r_key00')
  1232.         else:
  1233.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1234.             me.LaunchAnmType('tke_r_01')
  1235.     elif me.Data.last_heightdiff <= chartype.MaxTake2:
  1236.         if obj2inv:
  1237.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1238.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1239.             me.LaunchAnmType('tke_r_key01')
  1240.         else:
  1241.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1242.             me.LaunchAnmType('tke_r_02')
  1243.     elif me.Data.last_heightdiff <= chartype.MaxTake3:
  1244.         if obj2inv:
  1245.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1246.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1247.             me.LaunchAnmType('tke_r_key02')
  1248.         else:
  1249.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1250.             me.LaunchAnmType('tke_r_03')
  1251.     elif me.Data.last_heightdiff <= chartype.MaxTake4:
  1252.         if obj2inv:
  1253.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1254.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1255.             me.LaunchAnmType('tke_r_key03')
  1256.         else:
  1257.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1258.             me.LaunchAnmType('tke_r_04')
  1259.     elif me.Data.last_heightdiff <= chartype.MaxTake5:
  1260.         if obj2inv:
  1261.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1262.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1263.             me.LaunchAnmType('tke_r_key04')
  1264.         else:
  1265.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1266.             me.LaunchAnmType('tke_r_05')
  1267.     else:
  1268.         print 'Error in SubTake (last_height_diff) , Actions.py'
  1269.         if obj2inv:
  1270.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1271.             me.AddAnmEventFunc('Key_down', RemoveRightHandler)
  1272.             me.LaunchAnmType('tke_r_key04')
  1273.         else:
  1274.             me.AddAnmEventFunc('PickupEvent', PickupEventHandler)
  1275.             me.LaunchAnmType('tke_r_05')
  1276.     if obj2inv:
  1277.         me.AnmEndedFunc = TakeStraightRecover
  1278.     else:
  1279.         me.AnmEndedFunc = MainTake2Inv
  1280.     return TRUE
  1281.  
  1282.  
  1283. def TakeStraightRecover(EntityName):
  1284.     me = Bladex.GetEntity(EntityName)
  1285.     me.Data.toggle4t_clearback = TRUE
  1286.     if not (me.Data.stuff_onback_b4) and SthOnBack(EntityName) and me.InvRightBack and Reference.GiveObjectFlag(me.InvRightBack) == Reference.OBJ_QUIVER:
  1287.         me.AddAnmEventFunc('ChangeREvent', Toggle4TakingEvent)
  1288.         UnGraspString(EntityName, 'UnGraspString')
  1289.         me.LaunchAnmType('Chg_r')
  1290.     
  1291.  
  1292.  
  1293. def MainTake2Inv(EntityName):
  1294.     me = Bladex.GetEntity(EntityName)
  1295.     if not (me.Data) or not (me.Data.pickup_entity):
  1296.         return None
  1297.     
  1298.     object_name = me.Data.pickup_entity
  1299.     if IsRightHandStandardObject(EntityName):
  1300.         return None
  1301.     
  1302.     if IsRightHandAutomaticObject(EntityName):
  1303.         return None
  1304.     
  1305.     object_flag = Reference.GiveObjectFlag(object_name)
  1306.     if object_flag == Reference.OBJ_ARROW and me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) == Reference.OBJ_BOW:
  1307.         return None
  1308.     
  1309.     if not (me.Data.stuff_onback_b4) and not SthOnBack(EntityName) and IsRightHandWeaponObject(EntityName):
  1310.         return None
  1311.     
  1312.     ToggleAfterTakeObj(EntityName)
  1313.  
  1314.  
  1315. def PickupEventHandler(EntityName, EventName, force_take = TRUE):
  1316.     me = Bladex.GetEntity(EntityName)
  1317.     if EventName != 'PickupEvent':
  1318.         return None
  1319.     
  1320.     if not (me.Data) or not (me.Data.pickup_entity):
  1321.         return None
  1322.     
  1323.     if Bladex.GetEntity(me.Data.pickup_entity) == None:
  1324.         return None
  1325.     
  1326.     object_name = me.Data.pickup_entity
  1327.     dist = B3DLib.GetXZDistance(EntityName, object_name)
  1328.     chartype = Bladex.GetCharType(me.CharType, me.CharTypeExt)
  1329.     if dist > chartype.Reach:
  1330.         ReportMsg('Not in reach')
  1331.         return FALSE
  1332.     
  1333.     object = Bladex.GetEntity(object_name)
  1334.     if object.Parent:
  1335.         parent = Bladex.GetEntity(object.Parent)
  1336.         if parent.Person:
  1337.             return None
  1338.         
  1339.         parent.Unlink(object)
  1340.     
  1341.     Ontake.OnTakeFunc(object_name)
  1342.     Stars.DeTwinkle(object_name)
  1343.     me.Data.selected_entity = None
  1344.     me.DelAnmEventFunc(EventName)
  1345.     if IsOneTooMany(EntityName, object_name):
  1346.         if force_take:
  1347.             DropToMakeRoomFor(EntityName, object_name)
  1348.         else:
  1349.             print EntityName + ': Too many objects of this type: ' + object_name
  1350.             return None
  1351.     
  1352.     object_flag = Reference.GiveObjectFlag(object_name)
  1353.     inv = me.GetInventory()
  1354.     weapon_added = FALSE
  1355.     if not (me.InvRight):
  1356.         if object_flag == Reference.OBJ_WEAPON:
  1357.             flag = Reference.GiveWeaponFlag(object_name)
  1358.             inv.AddWeapon(object_name, flag)
  1359.             weapon_added = TRUE
  1360.             if not (me.Data.NPC) and not me.Data.WasObjectAlreadyTaken(object_name):
  1361.                 import Scorer
  1362.                 Scorer.SlideTBS(0)
  1363.             
  1364.         
  1365.         inv.LinkRightHand(object_name)
  1366.     
  1367.     if object_flag == Reference.OBJ_ITEM:
  1368.         ExtendedTakeObject(inv, object_name)
  1369.     elif object_flag == Reference.OBJ_SHIELD:
  1370.         inv.AddShield(object_name)
  1371.     elif object_flag == Reference.OBJ_WEAPON:
  1372.         if weapon_added == FALSE:
  1373.             flag = Reference.GiveWeaponFlag(object_name)
  1374.             inv.AddWeapon(object_name, flag)
  1375.             if not (me.Data.NPC) and not me.Data.WasObjectAlreadyTaken(object_name):
  1376.                 import Scorer
  1377.                 Scorer.SlideTBS(0)
  1378.             
  1379.         
  1380.     elif object_flag == Reference.OBJ_BOW:
  1381.         inv.AddBow(object_name)
  1382.     elif object_flag == Reference.OBJ_QUIVER:
  1383.         AddQuiver(inv, object_name)
  1384.     elif object_flag == Reference.OBJ_STANDARD:
  1385.         pass
  1386.     elif object_flag == Reference.OBJ_KEY:
  1387.         inv.AddKey(object_name)
  1388.     elif object_flag == Reference.OBJ_SPECIALKEY:
  1389.         inv.AddSpecialKey(object_name)
  1390.     elif object_flag == Reference.OBJ_TABLET:
  1391.         inv.AddTablet(object_name)
  1392.     elif object_flag == Reference.OBJ_USEME:
  1393.         if IsValidForUsing(object_name, EntityName):
  1394.             me.Data.obj_used = Bladex.GetEntity(object_name)
  1395.             object = Bladex.GetEntity(object_name)
  1396.             object.Data.UsedBy = EntityName
  1397.             object.UseFunc(object_name, USE_FROM_TAKE)
  1398.         
  1399.     elif object_flag == Reference.OBJ_ARROW and not (inv.HoldingBow):
  1400.         pass
  1401.     
  1402.     me.Data.RegisterObjectAsTaken(object_name)
  1403.  
  1404.  
  1405. def ThrowTime2ThrowForce(throw_pressed):
  1406.     curve_f = 3.0
  1407.     if throw_pressed < Reference.THROW_TIME_MIN:
  1408.         MinThrowForce = Reference.THROW_TIME_MIN / Reference.THROW_TIME_MAX
  1409.         MinThrowForce = pow(MinThrowForce, curve_f)
  1410.         ThrowForce = (throw_pressed / Reference.THROW_TIME_MIN) * MinThrowForce
  1411.     elif throw_pressed < Reference.THROW_TIME_MAX:
  1412.         ThrowForce = min(throw_pressed, Reference.THROW_TIME_MAX) / Reference.THROW_TIME_MAX
  1413.         ThrowForce = pow(ThrowForce, curve_f)
  1414.     else:
  1415.         ThrowForce = 1.0
  1416.     return ThrowForce
  1417.  
  1418.  
  1419. def TestThrowRight(EntityName):
  1420.     me = Bladex.GetEntity(EntityName)
  1421.     throw_pressed = Bladex.GetTimeActionHeld('Throw')
  1422.     if not throw_pressed:
  1423.         return None
  1424.     
  1425.     if throw_pressed < Reference.THROW_TIME_MIN:
  1426.         if netgame.GetNetState() != 2:
  1427.             TryDropRight(EntityName)
  1428.         else:
  1429.             netgame.SendUserString(Netval.NET_GAME_THROW_WEAPON, netgame.GetClientId() + ' ' + `-1`)
  1430.     elif netgame.GetNetState() != 2:
  1431.         me.Data.ThrowForce = ThrowTime2ThrowForce(throw_pressed)
  1432.         StdThrowObject(EntityName)
  1433.     else:
  1434.         netgame.SendUserString(Netval.NET_GAME_THROW_WEAPON, netgame.GetClientId() + ' ' + `ThrowTime2ThrowForce(throw_pressed)`)
  1435.  
  1436.  
  1437. def EnterThrowingMode(EntityName):
  1438.     pass
  1439.  
  1440.  
  1441. def TestThrowLeft(EntityName):
  1442.     me = Bladex.GetEntity(EntityName)
  1443.     throw_pressed = Bladex.GetTimeActionHeld('Throw')
  1444.     if not throw_pressed:
  1445.         return None
  1446.     
  1447.     TryDropLeft(EntityName)
  1448.  
  1449.  
  1450. def StdThrowObject(EntityName):
  1451.     me = Bladex.GetEntity(EntityName)
  1452.     statR = StatR(EntityName)
  1453.     if statR != RA_NO_WEAPON and statR != RA_BOW:
  1454.         object = Bladex.GetEntity(me.InvRight)
  1455.         if IsValidForThrowing(object.Name):
  1456.             object.ExcludeHitFor(me)
  1457.             mass = object.Mass
  1458.             if mass <= Reference.LightMassMax:
  1459.                 me.AddAnmEventFunc('ThrowLightFacingEvent', ThrowReleaseEventHandler)
  1460.                 me.LaunchAnmType('1tw_l_f')
  1461.             else:
  1462.                 me.AddAnmEventFunc('ThrowHeavyFacingEvent', ThrowReleaseEventHandler)
  1463.                 me.LaunchAnmType('1tw_h_f')
  1464.         else:
  1465.             ReportMsg('Cannot be thrown')
  1466.             StdDropObject(EntityName)
  1467.     
  1468.  
  1469.  
  1470. def RemoveFromInventory(me, object, EventName):
  1471.     me.Unlink(object)
  1472.     inv = me.GetInventory()
  1473.     object_name = object.Name
  1474.     if object_name == me.InvRight:
  1475.         me.RemoveFromInventRight()
  1476.     
  1477.     if object_name == me.InvLeft:
  1478.         me.RemoveFromInventLeft()
  1479.     
  1480.     object_flag = Reference.GiveObjectFlag(object_name)
  1481.     if object_flag == Reference.OBJ_ITEM:
  1482.         inv.RemoveObject(object_name)
  1483.     elif object_flag == Reference.OBJ_SHIELD:
  1484.         inv.RemoveShield(object_name)
  1485.     elif object_flag == Reference.OBJ_WEAPON:
  1486.         inv.RemoveWeapon(object_name)
  1487.     elif object_flag == Reference.OBJ_BOW:
  1488.         inv.RemoveBow(object_name)
  1489.     elif object_flag == Reference.OBJ_QUIVER:
  1490.         inv.RemoveQuiver(object_name)
  1491.     elif object_flag == Reference.OBJ_STANDARD:
  1492.         pass
  1493.     elif object_flag == Reference.OBJ_KEY:
  1494.         inv.RemoveKey(object_name)
  1495.     elif object_flag == Reference.OBJ_SPECIALKEY:
  1496.         inv.RemoveSpecialKey(object_name)
  1497.     elif object_flag == Reference.OBJ_TABLET:
  1498.         inv.RemoveTablet(object_name)
  1499.     elif object_flag == Reference.OBJ_USEME:
  1500.         pass
  1501.     
  1502.  
  1503.  
  1504. def ThrownWeaponStopFunc(EntityName):
  1505.     object = Bladex.GetEntity(EntityName)
  1506.     if object:
  1507.         object.MessageEvent(MESSAGE_STOP_WEAPON, 0, 0)
  1508.         object.MessageEvent(MESSAGE_STOP_TRAIL, 0, 0)
  1509.         
  1510.         try:
  1511.             if object.Data.PrevHitFunc:
  1512.                 object.HitFunc = object.Data.PrevHitFunc
  1513.                 object.Data.PrevHitFunc = None
  1514.                 object.HitFunc(EntityName)
  1515.         except AttributeError:
  1516.             pass
  1517.  
  1518.     
  1519.  
  1520.  
  1521. def ThrownWeaponInflictHitFunc(EntityName, VictimName, ImpX, ImpY, ImpZ):
  1522.     object = Bladex.GetEntity(EntityName)
  1523.     victim = Bladex.GetEntity(VictimName)
  1524.     print 'Thrown object hitting ' + VictimName
  1525.     object.MessageEvent(MESSAGE_STOP_WEAPON, 0, 0)
  1526.     if object.Data.PrevInflictHitFunc:
  1527.         object.InflictHitFunc = object.Data.PrevInflictHitFunc
  1528.         object.Data.PrevInflictHitFunc = None
  1529.         object.InflictHitFunc(EntityName, VictimName, ImpX, ImpY, ImpZ)
  1530.     else:
  1531.         object.InflictHitFunc = 0
  1532.  
  1533.  
  1534. def AutoCalcThrow(d, h, V, g):
  1535.     g2 = g ** 2
  1536.     V2 = V ** 2
  1537.     V4 = V ** 4
  1538.     d2 = d ** 2
  1539.     d4 = d ** 4
  1540.     a = h ** 2 + d2
  1541.     b = d2 * (-1.0 - h * g / V2)
  1542.     c = 0.25 * g2 * d4 / V4
  1543.     sq_term = b ** 2 - 4 * a * c
  1544.     if sq_term < 0.0:
  1545.         print "Auto calc doesn't reach"
  1546.         return (-PI * 0.25, 2.0)
  1547.     else:
  1548.         sq_term = math.sqrt(sq_term)
  1549.         k = (-b + sq_term) / (2.0 * a)
  1550.         angle = -math.acos(math.sqrt(k))
  1551.         time = d / (V * math.cos(angle))
  1552.         if abs(h - (V * math.sin(angle) * time + 0.5 * g * time * time)) > 0.001:
  1553.             angle = -angle
  1554.             time = d / (V * math.cos(angle))
  1555.         
  1556.         print 'Auto calc gives angle: ' + `angle` + ' with time: ' + `time`
  1557.         return (angle, time)
  1558.  
  1559.  
  1560. def ThrowReleaseEventHandler(EntityName, EventName):
  1561.     me = Bladex.GetEntity(EntityName)
  1562.     if EventName == 'ThrowLeftEvent':
  1563.         print 'LeftThrow'
  1564.         if me.InvLeft == 'None' or not (me.InvLeft):
  1565.             return None
  1566.         
  1567.         object = Bladex.GetEntity(me.InvLeft)
  1568.     elif me.InvRight == 'None' or not (me.InvRight):
  1569.         return None
  1570.     
  1571.     object = Bladex.GetEntity(me.InvRight)
  1572.     
  1573.     try:
  1574.         object.Data.ThrowReleaseEventHandler(me.Name, EventName)
  1575.     except AttributeError:
  1576.         if object.TestHit:
  1577.             return None
  1578.         
  1579.         RemoveFromInventory(me, object, EventName)
  1580.         F = me.Data.ThrowForce * 34000.0
  1581.         if me.InCombat:
  1582.             target = Bladex.GetEntity(me.ActiveEnemy)
  1583.             target_pos = target.Position
  1584.             source_pos = object.Position
  1585.             x = target_pos[0] - source_pos[0]
  1586.             y = target_pos[1] - source_pos[1]
  1587.             z = target_pos[2] - source_pos[2]
  1588.             (angle, time) = AutoCalcThrow(math.sqrt(x * x + z * z), y, F / object.Mass, +9800.0)
  1589.         elif EventName == 'ThrowLightFacingEvent':
  1590.             angle = -PI * 0.0625
  1591.         elif EventName == 'ThrowHeavyFacingEvent':
  1592.             angle = -PI * 0.125
  1593.         else:
  1594.             angle = -PI * 0.0625
  1595.         impulse = me.Rel2AbsVector(0.0, -math.cos(angle) * F, -math.sin(angle) * F)
  1596.         if me.InCombat:
  1597.             angle = B3DLib.Pos2PosXZAngle(source_pos[0], source_pos[1], source_pos[2], target_pos[0], target_pos[1], target_pos[2])
  1598.             diff_angle = min(max(B3DLib.DiffAngle(angle, me.Angle), -FACINGANGLE), FACINGANGLE)
  1599.             (x, y, z) = impulse
  1600.             cos_ang = math.cos(diff_angle)
  1601.             sin_ang = math.sin(diff_angle)
  1602.             impulse = (x * cos_ang - z * sin_ang, y, x * sin_ang + z * cos_ang)
  1603.         
  1604.         object.Impulse(impulse[0], impulse[1], impulse[2])
  1605.         throw_style = Reference.THR_SPINNING
  1606.         if Reference.EntitiesObjectData.has_key(object.Name):
  1607.             if Reference.EntitiesObjectData[object.Name][0] == Reference.OBJ_WEAPON or Reference.EntitiesObjectData[object.Name][0] == Reference.OBJ_STANDARD:
  1608.                 weaponData = Reference.EntitiesObjectData[object.Name]
  1609.                 if len(weaponData) > 4:
  1610.                     throw_style = weaponData[4]
  1611.                 
  1612.             
  1613.         else:
  1614.             kind = Bladex.GetEntity(object.Name).Kind
  1615.             if Reference.DefaultObjectData.has_key(kind):
  1616.                 if Reference.DefaultObjectData[kind][0] == Reference.OBJ_WEAPON or Reference.DefaultObjectData[kind][0] == Reference.OBJ_STANDARD:
  1617.                     weaponData = Reference.DefaultObjectData[kind]
  1618.                     if len(weaponData) > 4:
  1619.                         throw_style = weaponData[4]
  1620.                     
  1621.                 
  1622.             
  1623.         object.ExclusionMask = object.ExclusionMask | B_SOLID_MASK_PERSON
  1624.         if throw_style == Reference.THR_SPINNING:
  1625.             print object.AngularVelocity
  1626.             axis = object.GetDummyAxis('1H_R', 0.0, 1.0, 0.0)
  1627.             mass = object.Mass
  1628.             print mass
  1629.             scale = TWOPI * 10 / mass
  1630.             object.AngularVelocity = (axis[0] * scale, axis[1] * scale, axis[2] * scale)
  1631.         
  1632.         object.MessageEvent(MESSAGE_START_WEAPON, 0, 0)
  1633.         object.MessageEvent(MESSAGE_START_TRAIL, 0, 0)
  1634.         InitDataField.Initialise(object)
  1635.         object.Data.PrevHitFunc = None
  1636.         Bladex.AddScheduledFunc(Bladex.GetTime() + 2.0, ThrownWeaponStopFunc, (object.Name,), 'Stop Weapon: ' + object.Name)
  1637.         object.Data.PrevInflictHitFunc = object.InflictHitFunc
  1638.         object.InflictHitFunc = ThrownWeaponInflictHitFunc
  1639.         object.Data.ThrownBy = me
  1640.  
  1641.     me.DelAnmEventFunc(EventName)
  1642.  
  1643.  
  1644. def StdDropObject(EntityName):
  1645.     me = Bladex.GetEntity(EntityName)
  1646.     if TryDropRight(EntityName):
  1647.         pass
  1648.     elif TryDropLeft(EntityName):
  1649.         pass
  1650.     
  1651.  
  1652.  
  1653. def TryDropRight(EntityName):
  1654.     me = Bladex.GetEntity(EntityName)
  1655.     statR = StatR(EntityName)
  1656.     if statR != RA_NO_WEAPON:
  1657.         object = Bladex.GetEntity(me.InvRight)
  1658.         if IsValidForDropping(object.Name):
  1659.             object.ExcludeHitFor(me)
  1660.             if statR == RA_2H_OBJECT:
  1661.                 me.AddAnmEventFunc('Drop2HandedEvent', DropReleaseEventHandler)
  1662.                 me.LaunchAnmType('drp_2o')
  1663.                 return TRUE
  1664.             else:
  1665.                 me.AddAnmEventFunc('DropRightEvent', DropReleaseEventHandler)
  1666.                 me.Attack = 0
  1667.                 me.LaunchAnmType('drp_r')
  1668.                 return TRUE
  1669.         else:
  1670.             ReportMsg('Cannot be dropped')
  1671.             return FALSE
  1672.     else:
  1673.         return FALSE
  1674.  
  1675.  
  1676. def TryDropLeft(EntityName):
  1677.     me = Bladex.GetEntity(EntityName)
  1678.     statL = StatL(me.Name)
  1679.     if statL != LA_NO_WEAPON and statL != LA_BOW:
  1680.         object = Bladex.GetEntity(me.InvLeft)
  1681.         if IsValidForDropping(object.Name):
  1682.             object.ExcludeHitFor(me)
  1683.             me.AddAnmEventFunc('DropLeftEvent', DropReleaseEventHandler)
  1684.             me.LaunchAnmType('drp_l')
  1685.             return TRUE
  1686.         else:
  1687.             ReportMsg('Cannot be dropped')
  1688.     else:
  1689.         return FALSE
  1690.  
  1691.  
  1692. def DropReleaseEventHandler(EntityName, EventName, TestHit = TRUE):
  1693.     me = Bladex.GetEntity(EntityName)
  1694.     if EventName == 'DropLeftEvent':
  1695.         object = Bladex.GetEntity(me.InvLeft)
  1696.     else:
  1697.         object = Bladex.GetEntity(me.InvRight)
  1698.     
  1699.     try:
  1700.         object.Data.DropReleaseEventHandler(me.Name, EventName)
  1701.     except AttributeError:
  1702.         if TestHit and object.TestHit:
  1703.             return None
  1704.         
  1705.         RemoveFromInventory(me, object, EventName)
  1706.         if EventName == 'DropLeftEvent':
  1707.             impulse = me.Rel2AbsVector(500.0, -750.0, 0.0)
  1708.         elif EventName == 'Drop2HandedEvent':
  1709.             impulse = me.Rel2AbsVector(0.0, -750.0, 0.0)
  1710.         else:
  1711.             impulse = me.Rel2AbsVector(-1000.0, -1500.0, 0.0)
  1712.         object.Impulse(impulse[0], impulse[1], impulse[2])
  1713.         object.ExcludeHitFor(me)
  1714.         me.DelAnmEventFunc(EventName)
  1715.  
  1716.  
  1717.  
  1718. def SqDistanceToGpj(entity):
  1719.     return Gpj.SQDistance2(entity)
  1720.  
  1721.  
  1722. def SthOnBack(EntityName):
  1723.     me = Bladex.GetEntity(EntityName)
  1724.     if me.InvLeftBack:
  1725.         return TRUE
  1726.     
  1727.     if me.InvRightBack:
  1728.         if Reference.GiveObjectFlag(me.InvRightBack) == Reference.OBJ_QUIVER:
  1729.             return FALSE
  1730.         else:
  1731.             return TRUE
  1732.     else:
  1733.         return FALSE
  1734.  
  1735.  
  1736. def TwoHandedWeaponOnBack(EntityName):
  1737.     me = Bladex.GetEntity(EntityName)
  1738.     if SthOnBack(EntityName) and me.InvRightBack:
  1739.         back_object_flag = Reference.GiveObjectFlag(me.InvRightBack)
  1740.         if back_object_flag == Reference.OBJ_WEAPON:
  1741.             w_flag = Reference.GiveWeaponFlag(me.InvRightBack)
  1742.             if w_flag != Reference.W_FLAG_1H:
  1743.                 return TRUE
  1744.             
  1745.         
  1746.     
  1747.     return FALSE
  1748.  
  1749.  
  1750. def Left2InvEvent(pj_name, event):
  1751.     me = Bladex.GetEntity(pj_name)
  1752.     me.DelAnmEventFunc(event)
  1753.     inv = me.GetInventory()
  1754.     if me.InvLeft:
  1755.         inv.LinkLeftHand('None')
  1756.     
  1757.  
  1758.  
  1759. def Left2BackEvent(pj_name, event):
  1760.     me = Bladex.GetEntity(pj_name)
  1761.     me.DelAnmEventFunc(event)
  1762.     inv = me.GetInventory()
  1763.     if me.InvLeft:
  1764.         inv.LinkBack(me.InvLeft)
  1765.     
  1766.  
  1767.  
  1768. def ToggleWEvent(pj_name, event):
  1769.     me = Bladex.GetEntity(pj_name)
  1770.     if event == 'ChangeRLEvent':
  1771.         me.DelAnmEventFunc('ChangeRLEvent')
  1772.     elif event == 'ChangeREvent':
  1773.         me.DelAnmEventFunc('ChangeREvent')
  1774.     elif event == 'ChangeLEvent':
  1775.         me.DelAnmEventFunc('ChangeLEvent')
  1776.     else:
  1777.         print 'ToggleWEvent : Unexpected error! \n'
  1778.     inv = me.GetInventory()
  1779.     tmp_rback = me.InvRightBack
  1780.     tmp_lback = me.InvLeftBack
  1781.     if tmp_rback:
  1782.         if Reference.GiveObjectFlag(tmp_rback) == Reference.OBJ_QUIVER:
  1783.             tmp_rback = ''
  1784.         
  1785.     
  1786.     something_on_back = SthOnBack(pj_name)
  1787.     inv.LinkBack('None')
  1788.     add_quiver = 0
  1789.     if something_on_back and event == 'ChangeRLEvent' or event == 'ChangeREvent':
  1790.         if me.InvRight:
  1791.             inv.LinkRightHand('None')
  1792.         
  1793.         if tmp_lback and Reference.GiveObjectFlag(tmp_lback) == Reference.OBJ_BOW:
  1794.             add_quiver = 1
  1795.         
  1796.         if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) == Reference.OBJ_BOW:
  1797.             add_quiver = 1
  1798.         
  1799.     
  1800.     if event == 'ChangeRLEvent' or event == 'ChangeREvent':
  1801.         if me.InvRight:
  1802.             if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) == Reference.OBJ_BOW and me.InvRight and Reference.GiveObjectFlag(me.InvRight) == Reference.OBJ_ARROW:
  1803.                 SheatheArrow(inv, me.InvRight)
  1804.             else:
  1805.                 inv.LinkBack(me.InvRight)
  1806.         elif inv.HoldingBow:
  1807.             des_quiver_name = inv.GetSelectedQuiver()
  1808.             if des_quiver_name:
  1809.                 inv.SetCurrentQuiver(des_quiver_name)
  1810.                 inv.LinkBack(des_quiver_name)
  1811.             
  1812.         
  1813.         if not tmp_rback:
  1814.             inv.LinkRightHand('None')
  1815.         else:
  1816.             inv.LinkRightHand(tmp_rback)
  1817.             tmp_rback = ''
  1818.     
  1819.     if event == 'ChangeRLEvent' or event == 'ChangeLEvent':
  1820.         if tmp_rback:
  1821.             print 'Pseudo bug? ERROR , MIRAR'
  1822.             inv.LinkBack(tmp_rback)
  1823.         
  1824.         if me.InvLeft:
  1825.             inv.LinkBack(me.InvLeft)
  1826.         
  1827.         if not tmp_lback:
  1828.             inv.LinkLeftHand('None')
  1829.         else:
  1830.             inv.LinkLeftHand(tmp_lback)
  1831.     
  1832.     if add_quiver:
  1833.         UnSheatheArrow(inv)
  1834.     
  1835.  
  1836.  
  1837. def StdToggleWeapons(EntityName):
  1838.     me = Bladex.GetEntity(EntityName)
  1839.     if me.ActiveEnemy:
  1840.         me.SetActiveEnemy('')
  1841.         me.Data.time_deactive_enemy = Bladex.GetTime()
  1842.         return None
  1843.     
  1844.     if me.OnFloor == 0:
  1845.         return None
  1846.     
  1847.     if me.AnmEndedFunc:
  1848.         return FALSE
  1849.     
  1850.     inv = me.GetInventory()
  1851.     right_standard = IsRightHandStandardObject(EntityName)
  1852.     drop_right = 0
  1853.     if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) != Reference.OBJ_BOW and me.InvRightBack:
  1854.         if not (me.Attack) and not (me.Block):
  1855.             me.AddAnmEventFunc('ChangeLEvent', Left2BackEvent)
  1856.             me.LaunchAnmType('Chg_l')
  1857.             return None
  1858.         else:
  1859.             me.AddAnmEventFunc('ChangeREvent', ToggleWEvent)
  1860.             me.LaunchAnmType('Chg_r')
  1861.             return None
  1862.     elif me.InvRight and right_standard == 1:
  1863.         if (me.InvLeft or me.InvLeftBack) and me.InvRightBack:
  1864.             me.AddAnmEventFunc('ChangeLEvent', ToggleWEvent)
  1865.             me.LaunchAnmType('Chg_l')
  1866.             return None
  1867.         elif (me.InvRight and right_standard == 0 or me.InvRightBack) and me.InvLeft or me.InvLeftBack:
  1868.             drop_right = 1
  1869.         elif (me.InvRight and right_standard == 0 or me.InvRightBack) and not (me.InvLeft) and not (me.InvLeftBack):
  1870.             drop_right = 2
  1871.         elif not (me.InvRight) and not (me.InvRightBack) and me.InvLeft or me.InvLeftBack:
  1872.             if me.InvLeftBack and Reference.GiveObjectFlag(me.InvLeftBack) == Reference.OBJ_BOW:
  1873.                 me.AddAnmEventFunc('ChangeRLEvent', ToggleWEvent)
  1874.                 me.LaunchAnmType('Chg_r_l')
  1875.                 return None
  1876.             else:
  1877.                 me.AddAnmEventFunc('ChangeLEvent', ToggleWEvent)
  1878.                 me.LaunchAnmType('Chg_l')
  1879.                 return None
  1880.         else:
  1881.             return None
  1882.     if drop_right != 0 and IsRightHandStandardObject(EntityName):
  1883.         if TryDropRight(EntityName):
  1884.             DropReleaseEventHandler(EntityName, 'DropRightEvent')
  1885.         
  1886.         me.Wuea = Reference.WUEA_ENDED
  1887.     
  1888.     if drop_right == 1:
  1889.         me.AddAnmEventFunc('ChangeRLEvent', ToggleWEvent)
  1890.         me.LaunchAnmType('Chg_r_l')
  1891.     elif drop_right == 2:
  1892.         me.AddAnmEventFunc('ChangeREvent', ToggleWEvent)
  1893.         me.LaunchAnmType('Chg_r')
  1894.     else:
  1895.         print 'ERROR - ToggleW'
  1896.  
  1897.  
  1898. def FreeBothHands(EntityName, CallBack = None, Params = (), ForceNow = 1):
  1899.     me = Bladex.GetEntity(EntityName)
  1900.     if IsRightHandStandardObject(EntityName):
  1901.         if TryDropRight(EntityName):
  1902.             DropReleaseEventHandler(EntityName, 'DropRightEvent')
  1903.         
  1904.         me.Wuea = Reference.WUEA_ENDED
  1905.     
  1906.     if me.InvRight or me.InvLeft:
  1907.         if ForceNow:
  1908.             me.Wuea = Reference.WUEA_ENDED
  1909.             me.SetTmpAnmFlags(1, 1, 1, 0, 5, 1, 0)
  1910.             me.LaunchAnmType('rlx')
  1911.             me.Wuea = Reference.WUEA_ENDED
  1912.             me.SetTmpAnmFlags(1, 1, 1, 0, 5, 1, 0)
  1913.         
  1914.         StdToggleWeapons(EntityName)
  1915.         if CallBack:
  1916.             Bladex.AddScheduledFunc(Bladex.GetTime() + 2.0, CallBack, Params)
  1917.         
  1918.         return 0
  1919.     
  1920.     if CallBack:
  1921.         Bladex.AddScheduledFunc(Bladex.GetTime() + 0.1, CallBack, Params)
  1922.     
  1923.     return 1
  1924.  
  1925.  
  1926. def RelaxTurn180(EntityName):
  1927.     me = Bladex.GetEntity(EntityName)
  1928.     me.LaunchAnmType('rlx_turn')
  1929.  
  1930.  
  1931. def FrwdDown(EntityName):
  1932.     me = Bladex.GetEntity(EntityName)
  1933.     if netgame.GetNetState() != 2:
  1934.         if me.InCombat:
  1935.             return None
  1936.         
  1937.     
  1938.     diff = Bladex.GetTime() - me.Data.last_frwdup
  1939.     if diff > 0.0 and diff < 0.125:
  1940.         me = Bladex.GetEntity(EntityName)
  1941.         me.Run = 1
  1942.     
  1943.  
  1944.  
  1945. def FrwdUp(EntityName):
  1946.     me = Bladex.GetEntity(EntityName)
  1947.     if netgame.GetNetState() != 2:
  1948.         if me.InCombat:
  1949.             return None
  1950.         
  1951.     
  1952.     me.Data.last_frwdup = Bladex.GetTime()
  1953.     if me.Gob == FALSE:
  1954.         me.Run = 0
  1955.     
  1956.  
  1957.  
  1958. def BrwdDown(EntityName):
  1959.     me = Bladex.GetEntity(EntityName)
  1960.     if netgame.GetNetState() != 2:
  1961.         if me.InCombat:
  1962.             return None
  1963.         
  1964.     
  1965.     diff = Bladex.GetTime() - me.Data.last_brwdup
  1966.     if diff > 0.0 and diff < 0.125:
  1967.         me = Bladex.GetEntity(EntityName)
  1968.         me.Run = 1
  1969.     
  1970.  
  1971.  
  1972. def BrwdUp(EntityName):
  1973.     me = Bladex.GetEntity(EntityName)
  1974.     if netgame.GetNetState() != 2:
  1975.         if me.InCombat:
  1976.             return None
  1977.         
  1978.     
  1979.     me.Data.last_brwdup = Bladex.GetTime()
  1980.     if me.Gof == FALSE:
  1981.         me.Run = 0
  1982.     
  1983.  
  1984.  
  1985. def TakeArrowEventHandler(EntityName, EventName):
  1986.     me = Bladex.GetEntity(EntityName)
  1987.     if me:
  1988.         inv = me.GetInventory()
  1989.         UnSheatheArrow(inv)
  1990.     
  1991.  
  1992.  
  1993. def CurrentlyBowing(EntityName):
  1994.     me = Bladex.GetEntity(EntityName)
  1995.     anm = me.AnimName
  1996.     if not anm == 'B1' and anm == 'B2' and anm == 'B3' and anm == 'b1' and anm == 'b2':
  1997.         pass
  1998.     return anm == 'b3'
  1999.  
  2000.  
  2001. def InitBowing(EntityName):
  2002.     me = Bladex.GetEntity(EntityName)
  2003.     cam = Bladex.GetEntity('Camera')
  2004.     if EntityName == 'Player1':
  2005.         
  2006.         try:
  2007.             if me.Data.LastPViewType == None:
  2008.                 me.Data.LastPViewType = cam.PViewType
  2009.         except AttributeError:
  2010.             me.Data.LastPViewType = cam.PViewType
  2011.  
  2012.         
  2013.         try:
  2014.             if me.Data.LastReturns == None:
  2015.                 me.Data.LastReturns = me.Returns
  2016.         except AttributeError:
  2017.             me.Data.LastReturns = me.Returns
  2018.  
  2019.         cam.PViewType = 3
  2020.     
  2021.     me.Returns = 0
  2022.     me.Aim = 1
  2023.     me.Data.AimPressed = 1
  2024.     me.Accuracy = CharStats.GetCharAccuracy(me.Kind, me.Level)
  2025.     me.AimOffTarget = TWOPI
  2026.  
  2027.  
  2028. def TestDrawBow(EntityName):
  2029.     me = Bladex.GetEntity(EntityName)
  2030.     if me.Aim == 0 or not CurrentlyBowing(EntityName):
  2031.         if me.InvLeft and Reference.GiveObjectFlag(me.InvLeft) == Reference.OBJ_BOW:
  2032.             if me.Wuea == Reference.WUEA_WAIT:
  2033.                 if me.AnimName[:3] == 'Rlx' or me.AnimName[:3] == 'rlx':
  2034.                     me.Wuea = Reference.WUEA_NONE
  2035.                 else:
  2036.                     return None
  2037.             
  2038.             if me.InvRight and Reference.GiveObjectFlag(me.InvRight) == Reference.OBJ_ARROW:
  2039.                 InitBowing(EntityName)
  2040.                 GraspString(EntityName, 'GraspString')
  2041.                 me.SetTmpAnmFlags(1, 0, 1, 1, 2, 0)
  2042.                 me.LaunchAnmType('b1')
  2043.                 arrow = Bladex.GetEntity(me.InvRight)
  2044.                 tensar_sound = Bladex.CreateEntity(arrow.Name + 'RedrawSound', 'Entity Sound', 0, 0, 0)
  2045.                 tensar_sound.SetSound('..\\..\\Sounds\\M-CREAKCUERDA-3b.wav')
  2046.                 tensar_sound.MinDistance = 5000
  2047.                 tensar_sound.MaxDistance = 10000
  2048.                 arrow.Link(tensar_sound)
  2049.                 tensar_sound.PlaySound(0)
  2050.             elif not CurrentlyBowing(EntityName):
  2051.                 inv = me.GetInventory()
  2052.                 des_quiver_name = inv.GetSelectedQuiver()
  2053.                 if des_quiver_name:
  2054.                     inv.SetCurrentQuiver(des_quiver_name)
  2055.                     inv.LinkBack(des_quiver_name)
  2056.                     quiver = Bladex.GetEntity(des_quiver_name)
  2057.                     if quiver and quiver.Data.NumberOfArrows() > 0:
  2058.                         InitBowing(EntityName)
  2059.                         if me.Wuea == Reference.WUEA_WAIT:
  2060.                             print 'Trying to draw bow during other animation, wait and try again'
  2061.                         else:
  2062.                             me.LaunchAnmType('b2')
  2063.                     
  2064.                 
  2065.             
  2066.         
  2067.     
  2068.  
  2069.  
  2070. def EndBowMode(EntityName):
  2071.     me = Bladex.GetEntity(EntityName)
  2072.     
  2073.     try:
  2074.         if me.Data.LastPViewType != None:
  2075.             cam = Bladex.GetEntity('Camera')
  2076.             cam.PViewType = me.Data.LastPViewType
  2077.             me.Data.LastPViewType = None
  2078.     except AttributeError:
  2079.         pass
  2080.  
  2081.     
  2082.     try:
  2083.         if me.Data.LastReturns != None:
  2084.             me.Returns = me.Data.LastReturns
  2085.             me.Data.LastReturns = None
  2086.     except AttributeError:
  2087.         pass
  2088.  
  2089.     me.Aim = 0
  2090.     me.Data.AimPressed = 0
  2091.  
  2092.  
  2093. def TestReleaseArrow(EntityName):
  2094.     me = Bladex.GetEntity(EntityName)
  2095.     me.Data.AimPressed = 0
  2096.     if not CurrentlyBowing(EntityName):
  2097.         EndBowMode(EntityName)
  2098.     
  2099.  
  2100.  
  2101. def EndDrawBowEventHandler(EntityName, EventName):
  2102.     me = Bladex.GetEntity(EntityName)
  2103.     if me.Data.AimPressed == 0:
  2104.         me.Aim = 0
  2105.         arrow = Bladex.GetEntity(me.InvRight)
  2106.         if arrow:
  2107.             me.Unlink(arrow)
  2108.             me.RemoveFromInventRight()
  2109.             UnGraspString(EntityName, 'UnGraspString')
  2110.             arrow.ExcludeHitFor(me)
  2111.             arrow.PutToWorld()
  2112.             if me.Data.NPC:
  2113.                 (vx, vy, vz) = me.AimVector
  2114.             else:
  2115.                 (vx, vy, vz) = arrow.Rel2AbsVector(0, 0, -40000)
  2116.             arrow.Fly(vx, vy, vz)
  2117.             arrow.MessageEvent(MESSAGE_START_WEAPON, 0, 0)
  2118.             arrow.MessageEvent(MESSAGE_START_TRAIL, 0, 0)
  2119.             InitDataField.Initialise(arrow)
  2120.             Bladex.AddScheduledFunc(Bladex.GetTime() + 2.0, ThrownWeaponStopFunc, (arrow.Name,), 'Stop Weapon: ' + arrow.Name)
  2121.             arrow.Data.PrevInflictHitFunc = arrow.InflictHitFunc
  2122.             arrow.InflictHitFunc = ThrownWeaponInflictHitFunc
  2123.             arrow.Data.ThrownBy = me
  2124.             soltar_sound = Bladex.CreateEntity(arrow.Name + 'FlySound', 'Entity Sound', 0, 0, 0)
  2125.             soltar_sound.SetSound('..\\..\\Sounds\\ARCO-DISPARO-3.wav')
  2126.             soltar_sound.MinDistance = 5000
  2127.             soltar_sound.MaxDistance = 10000
  2128.             arrow.Link(soltar_sound)
  2129.             soltar_sound.PlaySound(0)
  2130.             me.SetTmpAnmFlags(1, 0, 1, 1, 2, 0)
  2131.             me.LaunchAnmType('b2')
  2132.             return None
  2133.         
  2134.     
  2135.     me.LaunchAnmType('b3')
  2136.  
  2137.  
  2138. def CheckRefireBowEventHandler(EntityName, EventName):
  2139.     me = Bladex.GetEntity(EntityName)
  2140.     if me.Data.AimPressed and me.InvRight:
  2141.         arrow = Bladex.GetEntity(me.InvRight)
  2142.         if arrow:
  2143.             GraspString(EntityName, 'GraspString')
  2144.             me.DoActionWI('b1', FixedFootAutoInterp, 0.3, 0.9)
  2145.             tensar_sound = Bladex.CreateEntity(arrow.Name + 'RedrawSound', 'Entity Sound', 0, 0, 0)
  2146.             tensar_sound.SetSound('..\\..\\Sounds\\M-CREAKCUERDA-4.wav')
  2147.             tensar_sound.MinDistance = 5000
  2148.             tensar_sound.MaxDistance = 10000
  2149.             arrow.Link(tensar_sound)
  2150.             tensar_sound.PlaySound(0)
  2151.             return None
  2152.         
  2153.     
  2154.     EndBowMode(EntityName)
  2155.  
  2156.  
  2157. def EndReloadBowEventHandler(EntityName, EventName):
  2158.     me = Bladex.GetEntity(EntityName)
  2159.     if me.Aim:
  2160.         me.DoAction('b1')
  2161.     elif not (me.InvRight):
  2162.         TakeArrowEventHandler(EntityName, EventName)
  2163.     
  2164.     me.LaunchAnmType('Rlx_b')
  2165.  
  2166.  
  2167. def FadeMeOut(EntityName, timer):
  2168.     if EntityName == 'Player1':
  2169.         return None
  2170.     
  2171.     me = Bladex.GetEntity(EntityName)
  2172.     current_alpha = me.Alpha
  2173.     if current_alpha > 0.0:
  2174.         current_alpha = current_alpha - 0.02
  2175.     else:
  2176.         me.Life = 0
  2177.         me.RemoveFromList('Timer60')
  2178.     if current_alpha < 0:
  2179.         current_alpha = 0
  2180.     
  2181.     me.Alpha = current_alpha
  2182.     if me.InvRight:
  2183.         right = Bladex.GetEntity(me.InvRight)
  2184.         right.Alpha = current_alpha
  2185.     
  2186.     if me.InvLeft:
  2187.         left = Bladex.GetEntity(me.InvLeft)
  2188.         left.Alpha = current_alpha
  2189.     
  2190.     if me.InvRightBack:
  2191.         right2 = Bladex.GetEntity(me.InvRightBack)
  2192.         right2.Alpha = current_alpha
  2193.     
  2194.     if me.InvLeftBack:
  2195.         left2 = Bladex.GetEntity(me.InvLeftBack)
  2196.         left2.Alpha = current_alpha
  2197.     
  2198.  
  2199.  
  2200. def ClientCallBack(id, type, cad):
  2201.     if type == Netval.NET_GAME_FADE_DUE2BIGFALL:
  2202.         if netgame.GetClientId() == cad:
  2203.             AuxFuncs.FadeTo(START_FADEOUT_IN_BIG_FALL, END_FADEOUT_IN_BIG_FALL)
  2204.         
  2205.     
  2206.  
  2207.  
  2208. def ServerCallBack(id, type, cad):
  2209.     if type == Netval.NET_GAME_THROW_WEAPON:
  2210.         if netgame.GetNetState() == 1:
  2211.             params = string.split(cad)
  2212.             me = Bladex.GetEntity(params[0])
  2213.             coso = string.atof(params[1])
  2214.             if coso == -1:
  2215.                 TryDropRight(params[0])
  2216.             else:
  2217.                 me.Data.ThrowForce = coso
  2218.                 StdThrowObject(params[0])
  2219.         
  2220.     
  2221.  
  2222.  
  2223. def StartFadingOutPlayer(EntityName):
  2224.     me = Bladex.GetEntity(EntityName)
  2225.     net_state = netgame.GetNetState()
  2226.     if net_state == 0:
  2227.         if EntityName == 'Player1' and me.WillCrashInFloor == 0:
  2228.             AuxFuncs.FadeTo(START_FADEOUT_IN_BIG_FALL, END_FADEOUT_IN_BIG_FALL)
  2229.         
  2230.     elif EntityName == 'Player1':
  2231.         if me.WillCrashInFloor == 0:
  2232.             AuxFuncs.FadeTo(START_FADEOUT_IN_BIG_FALL, END_FADEOUT_IN_BIG_FALL)
  2233.         
  2234.         netgame.SendUserString(Netval.NET_GAME_FADE_DUE2BIGFALL, EntityName)
  2235.     else:
  2236.         netgame.SendUserString(Netval.NET_GAME_FADE_DUE2BIGFALL, EntityName)
  2237.         me.TimerFunc = FadeMeOut
  2238.         me.SubscribeToList('Timer60')
  2239.  
  2240.  
  2241. def EndFadingOutPlayer(EntityName):
  2242.     me = Bladex.GetEntity(EntityName)
  2243.     me.Life = 0
  2244.     net_state = netgame.GetNetState()
  2245.     me.Wuea = Reference.WUEA_ENDED
  2246.     if net_state == 0:
  2247.         me.ImDeadFunc(me.Name)
  2248.         if EntityName == 'Player1':
  2249.             if me.WillCrashInFloor == 0:
  2250.                 int_pos = me.InitPos
  2251.                 me.Position = (int_pos[0], int_pos[1], int_pos[2])
  2252.             else:
  2253.                 int_pos = me.InitPos
  2254.                 me.Position = (int_pos[0], int_pos[1], int_pos[2])
  2255.         
  2256.     elif net_state == 1:
  2257.         me.Alpha = 1.0
  2258.         Damage.PlayerHitFunc(me.Name, 'BigFall', me.Life, 1)
  2259.     elif net_state == 2:
  2260.         me.Alpha = 1.0
  2261.     else:
  2262.         print 'Actions.py->EndFadingOutPlayer error . Unknown GetNetState()!!!'
  2263.  
  2264.  
  2265. def BackUpEnemy(EntityName, EventName):
  2266.     me = Bladex.GetEntity(EntityName)
  2267.     me.Data.TmpEnemy = me.ActiveEnemy
  2268.  
  2269.  
  2270. def Swap180Handler(EntityName, EventName):
  2271.     me = Bladex.GetEntity(EntityName)
  2272.     if me.Data and me.Data.TmpEnemy and me.Data.TmpEnemy == me.ActiveEnemy:
  2273.         me.SetActiveEnemy(None)
  2274.         if me.Data.selected_enemy:
  2275.             ene = Bladex.GetEntity(me.Data.selected_enemy[0])
  2276.             if me and ene.Person:
  2277.                 me.SetActiveEnemy(ene)
  2278.             
  2279.         
  2280.     elif me.Data.selected_enemy:
  2281.         ene = Bladex.GetEntity(me.Data.selected_enemy[0])
  2282.         if me and ene.Person:
  2283.             me.SetActiveEnemy(ene)
  2284.         
  2285.     
  2286.  
  2287.  
  2288. def EndTransitionFllHugeHandler(EntityName, EventName):
  2289.     me = Bladex.GetEntity(EntityName)
  2290.     Bladex.AddScheduledFunc(Bladex.GetTime() + 0.2, StartFadingOutPlayer, (EntityName,), 'StartFadingOutPlayer ' + EntityName)
  2291.     me.AnmEndedFunc = TakeMainAnm = EndFadingOutPlayer
  2292.  
  2293.  
  2294. def W2hToLeftHandler(EntityName, EventName):
  2295.     me = Bladex.GetEntity(EntityName)
  2296.     ObjectName = me.InvRight
  2297.     if ObjectName == 'None' or not ObjectName:
  2298.         print 'W2hToLeftHandle-> Event in a unexpected situation!!! Entity ' + EntityName + ' in animation ' + me.AnimName
  2299.         return None
  2300.     
  2301.     inv = me.GetInventory()
  2302.     inv.LinkRightHand('None')
  2303.     object = Bladex.GetEntity(ObjectName)
  2304.     node = me.GetNodeIndex('L_Hand')
  2305.     me.LinkToNode(object, node)
  2306.     me.Data.TmpW2h = ObjectName
  2307.  
  2308.  
  2309. def W2hToRightHandler(EntityName, EventName):
  2310.     me = Bladex.GetEntity(EntityName)
  2311.     if not ('TmpW2h' in dir(me.Data)):
  2312.         me.Data.TmpW2h = ''
  2313.         return None
  2314.     
  2315.     if me.Data.TmpW2h == None:
  2316.         return None
  2317.     
  2318.     if me.Data.TmpW2h == '':
  2319.         return None
  2320.     
  2321.     inv = me.GetInventory()
  2322.     object = Bladex.GetEntity(me.Data.TmpW2h)
  2323.     me.Unlink(object)
  2324.     inv.LinkLeftHand('None')
  2325.     inv.LinkRightHand(me.Data.TmpW2h)
  2326.     me.Data.TmpW2h = ''
  2327.  
  2328.  
  2329. def AutoTake(EntityName):
  2330.     me = Bladex.GetEntity(EntityName)
  2331.     if me.InvRight:
  2332.         if not FreeBothHands(EntityName, None, (), 0):
  2333.             return None
  2334.         
  2335.     
  2336.     head_pos = me.Rel2AbsPoint(0.0, 0.0, 0.0)
  2337.     pj_dir = me.Rel2AbsVector(0.0, -1.0, 0.0)
  2338.     list = Bladex.GetObjectEntitiesVisibleFrom(head_pos, 5000.0, pj_dir, 0.0)
  2339.     for n in list:
  2340.         o = Bladex.GetEntity(n)
  2341.     
  2342.  
  2343.  
  2344. def ToggleIAttackRight(EntityName, event):
  2345.     me = Bladex.GetEntity(EntityName)
  2346.     if not (me.InvRightBack) or me.InvRightBack == '':
  2347.         print 'Error in Actions.ToggleIAttackRight'
  2348.         return None
  2349.     
  2350.     inv = me.GetInventory()
  2351.     tmpr_back = me.InvRightBack
  2352.     inv.LinkRightBack('None')
  2353.     inv.LinkRightHand(tmpr_back)
  2354.     if not (me.InCombat):
  2355.         import DefaultSelectionData
  2356.         DefaultSelectionData.SelectEnemy()
  2357.     
  2358.  
  2359.  
  2360. def ToggleIAttackLeft(EntityName, event):
  2361.     me = Bladex.GetEntity(EntityName)
  2362.     if not (me.InvLeftBack) or me.InvLeftBack == '':
  2363.         return None
  2364.     
  2365.     inv = me.GetInventory()
  2366.     tmpl_back = me.InvLeftBack
  2367.     inv.LinkLeftBack('None')
  2368.     inv.LinkLeftHand(tmpl_back)
  2369.  
  2370.  
  2371. def InstantAttackSlow(EntityName, EventName):
  2372.     me = Bladex.GetEntity(EntityName)
  2373.     if not (me.Data.NPC) and me.GotAnmType('g_draw_rlx'):
  2374.         me.AddAnmEventFunc('ChangeREvent', ToggleIAttackRight)
  2375.         me.AddAnmEventFunc('ChangeLEvent', ToggleIAttackLeft)
  2376.         me.AttackFunc(EntityName, 'g_draw_rlx')
  2377.     elif not (me.Data.NPC):
  2378.         print 'No instant attack for not having the animation!! ----3D Dept---' + EntityName
  2379.     
  2380.  
  2381.  
  2382. def InstantAttackRun(EntityName, EventName):
  2383.     me = Bladex.GetEntity(EntityName)
  2384.     if me.GotAnmType('g_draw_run'):
  2385.         me.AddAnmEventFunc('ChangeREvent', ToggleIAttackRight)
  2386.         me.AddAnmEventFunc('ChangeLEvent', ToggleIAttackLeft)
  2387.         me.AttackFunc(EntityName, 'g_draw_run')
  2388.     elif me.Data.NPC == 0:
  2389.         print 'No instant attack for not having the animation!! ----3D Dept---' + EntityName
  2390.     
  2391.  
  2392.  
  2393. def LinkContinuosSoundAux(csound):
  2394.     csound.PlaySound(-1)
  2395.  
  2396.  
  2397. def LinkContinuosSound(EntityName, SoundName, max_dist = 12000, min_dist = 5000):
  2398.     me = Bladex.GetEntity(EntityName)
  2399.     csound = Bladex.CreateEntity(EntityName + 'ContinuosSound', 'Entity Sound', 0, 0, 0)
  2400.     csound.SetSound(SoundName)
  2401.     csound.MinDistance = min_dist
  2402.     csound.MaxDistance = max_dist
  2403.     me.Link(csound)
  2404.     Bladex.AddScheduledFunc(Bladex.GetTime() + 1.0, LinkContinuosSoundAux, (csound,), 'LinkContinuosSoundAux')
  2405.  
  2406.  
  2407. def CicloDeluz(PersonName, val):
  2408.     per = Bladex.GetEntity(PersonName)
  2409.     if per:
  2410.         if val < 1.0:
  2411.             per.SelfIlum = val
  2412.             Bladex.AddScheduledFunc(Bladex.GetTime() + 0.1, CicloDeluz, (PersonName, val + 0.1))
  2413.             wps = Bladex.GetEntity(PersonName + 'WPS')
  2414.             if wps:
  2415.                 wps.PPS = wps.PPS + 25
  2416.             
  2417.         elif val < 2.0:
  2418.             per.Alpha = -val + 1.9
  2419.             Bladex.AddScheduledFunc(Bladex.GetTime() + 0.1, CicloDeluz, (PersonName, val + 0.1))
  2420.         
  2421.     
  2422.  
  2423.  
  2424. def HumoDeFuego(PersonName):
  2425.     per = Bladex.GetEntity(PersonName)
  2426.     if per:
  2427.         wps = Bladex.CreateEntity(PersonName + 'WPSmk', 'Entity Particle System Dperson', 0.0, 0.0, 0.0)
  2428.         wps.PersonName = PersonName
  2429.         wps.ParticleType = 'DarkSmoke'
  2430.         wps.Time2Live = 96
  2431.         wps.RandomVelocity = 0
  2432.         wps.Velocity = (0, 0, 0)
  2433.         wps.NormalVelocity = 5
  2434.         wps.YGravity = 0
  2435.         wps.PPS = 125
  2436.         wps.DeathTime = Bladex.GetTime() + 1.0
  2437.     
  2438.  
  2439.  
  2440. def FreezeMeGuy(PersonName):
  2441.     per = Bladex.GetEntity(PersonName)
  2442.     per.Freeze()
  2443.     per.RemoveFromWorld()
  2444.  
  2445.  
  2446. def RePutTheFuckingEndFunction(PersonName):
  2447.     per = Bladex.GetEntity(PersonName)
  2448.     per.AnmEndedFunc = FreezeMeGuy
  2449.  
  2450.  
  2451. def FireDeath(PersonName = 'Player1', ParType = 'LargeFire', NumPart = 32):
  2452.     TIME_TO_FIRE = 12.0
  2453.     per = Bladex.GetEntity(PersonName)
  2454.     if per:
  2455.         wps = Bladex.CreateEntity(PersonName + 'WPS', 'Entity Particle System Dperson', 0.0, 0.0, 0.0)
  2456.         wps.PersonName = PersonName
  2457.         wps.ParticleType = ParType
  2458.         wps.Time2Live = NumPart
  2459.         wps.RandomVelocity = 1.0
  2460.         wps.Velocity = (0, -300, 0)
  2461.         wps.NormalVelocity = 3
  2462.         wps.YGravity = 0
  2463.         wps.PPS = 200
  2464.         wps.DeathTime = Bladex.GetTime() + TIME_TO_FIRE
  2465.         per.SelfIlum = 0.0
  2466.         per.Alpha = 1.0
  2467.         Bladex.AddScheduledFunc(Bladex.GetTime() + TIME_TO_FIRE - 2, CicloDeluz, (PersonName, 0))
  2468.         Bladex.AddScheduledFunc(Bladex.GetTime() + TIME_TO_FIRE - 0, HumoDeFuego, (PersonName,))
  2469.         Bladex.AddScheduledFunc(Bladex.GetTime() + 1.5, RePutTheFuckingEndFunction, (PersonName,))
  2470.         per.LaunchAnmType('dth_burn')
  2471.         per.AnmEndedFunc = FreezeMeGuy
  2472.     
  2473.  
  2474.  
  2475. def ToggleInvincibility():
  2476.     me = Bladex.GetEntity('Player1')
  2477.     
  2478.     try:
  2479.         if me:
  2480.             if not (me.Data.Invincibility):
  2481.                 import pocimac
  2482.                 me.Life = CharStats.GetCharMaxLife(me.Kind, me.Level)
  2483.                 pocimac.RestoreWoundsToLifeLevel(me.Name)
  2484.                 me.Data.Invincibility = TRUE
  2485.                 ReportMsg('Enabling INVINCIBILITY mode')
  2486.             else:
  2487.                 me.Data.Invincibility = FALSE
  2488.                 ReportMsg('Disabling INVINCIBILITY mode')
  2489.     except AttributeError:
  2490.         pass
  2491.  
  2492.  
  2493. profiler_on = 1
  2494.  
  2495. def ToggleProfiling():
  2496.     global profiler_on
  2497.     profiler_on = not profiler_on
  2498.     if not profiler_on:
  2499.         print 'Switching off Profiler'
  2500.         Bladex.SetCallCheck(3)
  2501.         Bladex.SaveProfileData('Profile.txt')
  2502.         Bladex.StartProfile()
  2503.         Bladex.DisableProfiler()
  2504.     else:
  2505.         print 'Switching on Profiler'
  2506.         Bladex.SetCallCheck(11)
  2507.         Bladex.EnableProfiler()
  2508.         Bladex.StartProfile()
  2509.  
  2510.