Advertisement
Guest User

Untitled

a guest
Sep 29th, 2013
3,602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. -- Interact through walls
  2. function ObjectInteractionManager:interact( player )
  3. if( alive( self._active_object ) ) then
  4. local interacted,timer = self._active_object:interaction():interact_start( player )
  5. if timer then
  6. self._active_object_locked_data = true
  7. end
  8. return interacted or interacted == nil or false, timer, self._active_object
  9. end
  10. return false
  11. end
  12. local mvec1 = Vector3()
  13. function ObjectInteractionManager:_update_targeted( player_pos, player_unit )
  14. local mvec3_dis = mvector3.distance
  15. --clean out far away objects
  16. if( #self._close_objects > 0 ) then
  17. for k, v in pairs( self._close_objects ) do
  18. if( alive( v ) and v:interaction():active() ) then
  19. if mvec3_dis( player_pos, v:interaction():interact_position() ) > v:interaction():interact_distance() then
  20. table.remove( self._close_objects, k )
  21. end
  22. else
  23. table.remove( self._close_objects, k )
  24. end
  25. end
  26. end
  27.  
  28. --check for new objects
  29. for i = 1, self._close_freq, 1 do
  30. if( self._close_index >= self._interactive_count ) then
  31. self._close_index = 1
  32. else
  33. self._close_index = self._close_index + 1
  34. end
  35.  
  36. local obj = self._interactive_objects[ self._close_index ]
  37. if( alive(obj) and obj:interaction():active() and not self:_in_close_list( obj ) ) then
  38. if( mvec3_dis(player_pos, obj:interaction():interact_position()) <= obj:interaction():interact_distance() ) then
  39. table.insert( self._close_objects, obj )
  40. end
  41. end
  42. end
  43.  
  44. -- local locked = self._active_object_locked_data and alive( self._active_object )
  45. local locked = false
  46. if self._active_object_locked_data then
  47. if not alive( self._active_object ) or not self._active_object:interaction():active() then
  48. self._active_object_locked_data = nil
  49. else
  50. -- print( "dist", mvec3_dis(player_pos, self._active_object:interaction():interact_position()) )
  51. -- locked = ( mvec3_dis(player_pos, self._active_object:interaction():interact_position()) - self._active_object_locked_data.distance ) < 20
  52. locked = ( mvec3_dis(player_pos, self._active_object:interaction():interact_position()) <= self._active_object:interaction():interact_distance() )
  53. end
  54. end
  55.  
  56. if locked then
  57. return
  58. end
  59.  
  60. local last_active = self._active_object
  61. local blocked = player_unit:movement():object_interaction_blocked()
  62. if( #self._close_objects > 0 ) and not blocked then
  63. --find the one the player is looking at
  64. local active_obj = nil
  65. local current_dot = 0.9
  66.  
  67. local player_fwd = player_unit:camera():forward()
  68. local camera_pos = player_unit:camera():position()
  69. for k, v in pairs( self._close_objects ) do
  70. if( alive( v ) ) then
  71. mvector3.set( mvec1, v:interaction():interact_position() )
  72. mvector3.subtract( mvec1, camera_pos )
  73. mvector3.normalize( mvec1 )
  74. local dot = mvector3.dot( player_fwd, mvec1 )
  75. if( dot > current_dot ) then
  76. current_dot = dot
  77. active_obj = v
  78. end
  79. end
  80. end
  81.  
  82. if( active_obj and self._active_object ~= active_obj ) then
  83. if alive( self._active_object ) then
  84. self._active_object:interaction():unselect()
  85. end
  86. if not active_obj:interaction():selected( player_unit ) then
  87. active_obj = nil
  88. end
  89. end
  90. self._active_object = active_obj
  91. else
  92. self._active_object = nil
  93. end
  94.  
  95. --unselect the last one
  96. if( alive( last_active ) ) then
  97. if( not self._active_object ) then
  98. self._active_object = nil
  99. last_active:interaction():unselect()
  100. end
  101. end
  102. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement