home *** CD-ROM | disk | FTP | other *** search
/ PC PowerPlay 56 / CDPowerplay56Disc2.iso / demos / blade / data1.cab / Program_Executable_Files / Lib / Actions.py < prev    next >
Encoding:
Text File  |  2000-10-27  |  83.1 KB  |  2,828 lines

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