File size: 25,782 Bytes
24b81cb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 |
enum ActionConditionMask
{
ACM_NO_EXEPTION = 0,
ACM_IN_VEHICLE = 1,
ACM_ON_LADDER = 2,
ACM_SWIMMING = 4,
ACM_RESTRAIN = 8,
ACM_RAISED = 16,
ACM_ON_BACK = 32,
ACM_THROWING = 64,
ACM_LEANING = 128,
ACM_BROKEN_LEGS = 256,
}
class ActionReciveData
{
ItemBase m_MainItem;
ref ActionTarget m_Target;
}
class ActionData
{
void ActionData()
{
m_State = UA_NONE;
}
ref ActionBase m_Action;
ItemBase m_MainItem;
ActionBaseCB m_Callback;
ref CABase m_ActionComponent;
int m_State;
ref ActionTarget m_Target;
PlayerBase m_Player;
int m_PossibleStanceMask;
ref array<ref InventoryLocation> m_ReservedInventoryLocations;
int m_RefreshReservationTimer;
int m_RefreshJunctureTimer;
bool m_WasExecuted;
bool m_WasActionStarted;
bool m_ReciveEndInput;
}
class ActionBase : ActionBase_Basic
{
//STATIC DATA
protected int m_RefreshReservationTimerValue = 140;
// Configurable action parameters
protected string m_Sound; //sound played at the beggining of action
protected string m_Text;
protected bool m_LockTargetOnUse; //this parameter sets wheter player can perform actions on target while other player is already performing action on it. defaulted as true
protected bool m_FullBody; //tells whether action is full body or additive
protected int m_StanceMask;
protected ref TStringArray m_Sounds; //User action sound is picked from this array randomly
ref CCIBase m_ConditionItem; //Condition Component
ref CCTBase m_ConditionTarget; //Condition Component
protected ActionInput m_Input;
protected int m_ActionID;
protected int m_VariantID;
int m_ConditionMask;
protected ref ActionVariantManager m_VariantManager;
//RUNTIME DATA
protected ref Param1<string> m_MessageParam; //used for passing messages from server to client
//protected ref Param2<int,int> m_MessagesParam;
//SOFT SKILLS
protected float m_SpecialtyWeight;
//-----------------------------------------------------
// Action events and methods
//-----------------------------------------------------
void ActionBase()
{
// definable
m_StanceMask = DayZPlayerConstants.STANCEMASK_ERECT | DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_PRONE;
m_FullBody = false;
m_Sound = "";
m_Text = "default action text";
m_LockTargetOnUse = HasTarget();
// dont override
m_MessageParam = new Param1<string>("");
//m_MessagesParam = new Param2<int,int>(0,0);
m_Sounds = new TStringArray;
m_Input = null;
m_ActionID = 0;
InitConditionMask();
}
bool IsLockTargetOnUse()
{
return m_LockTargetOnUse;
}
void InitConditionMask()
{
m_ConditionMask = ActionConditionMask.ACM_NO_EXEPTION;
if (CanBeUsedInVehicle())
{
m_ConditionMask |= ActionConditionMask.ACM_IN_VEHICLE;
}
if (CanBeUsedOnLadder())
{
m_ConditionMask |= ActionConditionMask.ACM_ON_LADDER;
}
if (CanBeUsedSwimming())
{
m_ConditionMask |= ActionConditionMask.ACM_SWIMMING;
}
if (CanBeUsedInRestrain())
{
m_ConditionMask |= ActionConditionMask.ACM_RESTRAIN;
}
if (CanBeUsedRaised())
{
m_ConditionMask |= ActionConditionMask.ACM_RAISED;
}
if (CanBeUsedOnBack())
{
m_ConditionMask |= ActionConditionMask.ACM_ON_BACK;
}
if (CanBeUsedThrowing())
{
m_ConditionMask |= ActionConditionMask.ACM_THROWING;
}
if (CanBeUsedLeaning())
{
m_ConditionMask |= ActionConditionMask.ACM_LEANING;
}
if (CanBeUsedWithBrokenLegs())
{
m_ConditionMask |= ActionConditionMask.ACM_BROKEN_LEGS;
}
}
bool SetupAction(PlayerBase player, ActionTarget target, ItemBase item, out ActionData action_data, Param extra_data = NULL )
{
action_data = CreateActionData();
action_data.m_Action = this;
action_data.m_Player = player;
action_data.m_Target = target;
action_data.m_MainItem = item;
action_data.m_PossibleStanceMask = GetStanceMask(player);
action_data.m_ReservedInventoryLocations = new array<ref InventoryLocation>;
action_data.m_RefreshReservationTimer = m_RefreshReservationTimerValue;
action_data.m_WasExecuted = false;
action_data.m_WasActionStarted = false;
action_data.m_ReciveEndInput = false;
ActionReciveData action_recive_data = player.GetActionManager().GetReciveData();
if ( action_recive_data )
{
HandleReciveData(action_recive_data,action_data);
if ( UseMainItem() && MainItemAlwaysInHands() )
{
if ( player.GetItemInHands() != action_data.m_MainItem )
{
return false;
}
}
}
if ( !Post_SetupAction( action_data ) )
return false;
if ( (!GetGame().IsDedicatedServer()) && !IsInstant() )
{
if (!InventoryReservation(action_data))
{
ClearInventoryReservationEx(action_data);
return false;
}
if ( LogManager.IsActionLogEnable() )
{
for ( int i = 0; i < action_data.m_ReservedInventoryLocations.Count(); i++)
{
Debug.ActionLog( InventoryLocation.DumpToStringNullSafe( action_data.m_ReservedInventoryLocations[i] ), action_data.m_Action.ToString() , "n/a", "LockInventoryList", action_data.m_Player.ToString() );
}
}
}
return true;
}
bool Post_SetupAction( ActionData action_data )
{
return true;
}
void ActionCleanup( ActionData action_data )
{}
typename GetInputType()
{
return DefaultActionInput;
}
void SetInput( ActionInput ai)
{
m_Input = ai;
}
ActionData CreateActionData()
{
return new ActionData;
}
void CreateConditionComponents() //Instantiates components, called once from ActionManager on actions construction
{
m_ConditionItem = new CCIDummy;
m_ConditionTarget = new CCTDummy;
}
Object GetDisplayInteractObject(PlayerBase player, ActionTarget target)
{
return null;
}
//! Action is performed on target, not with item itself, when set to true.
//! * target will be synced to server
//! * UI: floating widget will be displayed at target pos
bool HasTarget()
{
return true;
}
//! For UI: hiding of progress bar
bool HasProgress()
{
return true;
}
//Action isn't synchronize to server
bool IsLocal()
{
return false;
}
//Action not using animation/callback action are executed instantly (OnStart)
bool IsInstant()
{
return false;
}
//! not using plane object - it's using multiple proxies
bool IsUsingProxies()
{
return false;
}
bool RemoveForceTargetAfterUse()
{
return true;
}
int GetActionCategory()
{
return AC_UNCATEGORIZED;
}
bool IsEat()
{
return false;
}
bool IsDrink()
{
return false;
}
bool IsShaveSelf()
{
return false;
}
string GetText() //text game displays in HUD hint
{
return m_Text;
}
bool CanBePerformedFromQuickbar()
{
return false;
}
bool CanBePerformedFromInventory()
{
return false;
}
bool CanBeSetFromInventory()
{
return !CanBePerformedFromInventory();
}
bool CanBeUsedInRestrain()
{
return false;
}
bool CanBeUsedInVehicle()
{
return false;
}
bool CanBeUsedOnBack()
{
return false;
}
bool CanBeUsedSwimming()
{
return false;
}
bool CanBeUsedOnLadder()
{
return false;
}
bool CanBeUsedRaised()
{
return false;
}
bool CanBeUsedThrowing()
{
return false;
}
bool CanBeUsedLeaning()
{
return true;
}
bool CanBeUsedWithBrokenLegs()
{
return true;
}
//! Is an action directly related to deployment/advanced placing
bool IsDeploymentAction()
{
return false;
}
bool UseMainItem()
{
return true;
}
bool MainItemAlwaysInHands()
{
return true;
}
protected bool ActionConditionContinue( ActionData action_data ) //condition for action
{
return ActionCondition(action_data.m_Player,action_data.m_Target,action_data.m_MainItem);
}
protected bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item ) //condition for action
{
return true;
}
void ApplyModifiers(ActionData action_data);
int GetRefreshReservationTimerValue()
{
return m_RefreshReservationTimerValue;
}
void WriteToContext(ParamsWriteContext ctx, ActionData action_data)
{
int componentIndex = -1;
int proxyBoneIdx = -1;
vector cursorHitPos = vector.Zero;
array<string> selectionNames = new array<string>();
Object targetObject = null;
Object targetParent = null;
if (UseMainItem())
{
ctx.Write(action_data.m_MainItem);
}
if (HasTarget() && !IsUsingProxies())
{
// callback data
targetObject = action_data.m_Target.GetObject();
ctx.Write(targetObject);
targetParent = action_data.m_Target.GetParent();
ctx.Write(targetParent);
componentIndex = action_data.m_Target.GetComponentIndex();
ctx.Write(componentIndex);
cursorHitPos = action_data.m_Target.GetCursorHitPos();
ctx.Write(cursorHitPos);
}
else if( HasTarget() && IsUsingProxies() )
{
//! get proxy bone idx from parent and selection we are looking at
//! ID is used for synchronisation to server where it's translated back to object
Entity entParent = Entity.Cast(action_data.m_Target.GetParent());
if (entParent)
{
action_data.m_Target.GetObject().GetActionComponentNameList(action_data.m_Target.GetComponentIndex(), selectionNames);
for (int s = 0; s < selectionNames.Count(); s++)
{
proxyBoneIdx = entParent.GetBoneIndex(selectionNames[s]);
if( proxyBoneIdx > -1 )
{
break;
}
}
}
ctx.Write(proxyBoneIdx);
targetParent = action_data.m_Target.GetParent();
ctx.Write(targetParent);
componentIndex = action_data.m_Target.GetComponentIndex();
ctx.Write(componentIndex);
cursorHitPos = action_data.m_Target.GetCursorHitPos();
ctx.Write(cursorHitPos);
}
}
bool ReadFromContext(ParamsReadContext ctx, out ActionReciveData action_recive_data )
{
if ( !action_recive_data )
{
action_recive_data = new ActionReciveData;
}
Object actionTargetObject = null;
Object actionTargetParent = null;
int componentIndex = -1;
int proxyBoneIdx = -1;
vector cursorHitPos = vector.Zero;
ItemBase mainItem = null;
ref ActionTarget target;
if ( UseMainItem() )
{
if ( !ctx.Read(mainItem) )
return false;
}
if ( HasTarget() && !IsUsingProxies() )
{
if ( !ctx.Read(actionTargetObject) )
return false;
if ( !ctx.Read(actionTargetParent))
return false;
if ( !ctx.Read(componentIndex) )
return false;
if ( !ctx.Read(cursorHitPos) )
return false;
target = new ActionTarget(actionTargetObject, actionTargetParent, componentIndex, cursorHitPos, 0);
action_recive_data.m_Target = target;
}
else if( HasTarget() && IsUsingProxies() )
{
if ( !ctx.Read(proxyBoneIdx) )
return false;
if ( !ctx.Read(actionTargetParent))
return false;
if ( !ctx.Read(componentIndex) )
return false;
if ( !ctx.Read(cursorHitPos) )
return false;
//! create target object from proxyBoneIdx synced from client
if ( proxyBoneIdx > -1 )
{
Entity entParent = Entity.Cast(actionTargetParent);
if (entParent)
{
actionTargetObject = entParent.GetBoneObject(proxyBoneIdx);
}
}
else
{
return false;
}
target = new ActionTarget(actionTargetObject, actionTargetParent, componentIndex, cursorHitPos, 0);
action_recive_data.m_Target = target;
}
action_recive_data.m_MainItem = mainItem;
return true;
}
void HandleReciveData(ActionReciveData action_recive_data, ActionData action_data)
{
action_data.m_MainItem = action_recive_data.m_MainItem;
if(HasTarget())
{
if (action_recive_data.m_Target)
{
action_data.m_Target = action_recive_data.m_Target;
}
else
{
Error("Action target not created.");
action_data.m_Target = new ActionTarget(NULL, NULL, -1, vector.Zero, 0);
}
}
}
//----------------------------------------------------------------------------------------------
// Core methods don't override unless you know what you are doing
//----------------------------------------------------------------------------------------------
// COMMANDS -----------------------------------------------------------------------
protected int GetStanceMask(PlayerBase player)
{
if ( HasProneException() )
{
if ( player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_RAISEDERECT | DayZPlayerConstants.STANCEMASK_RAISEDCROUCH | DayZPlayerConstants.STANCEMASK_RAISEDPRONE))
return -1;
else if ( player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT))
return DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT;
else
return DayZPlayerConstants.STANCEMASK_PRONE;
}
return m_StanceMask;
}
bool IsFullBody(PlayerBase player)
{
if ( HasProneException() )
{
return !( player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT) );
}
return m_FullBody;
}
// if it is set to true if action have special fullbody animation for prone and additive for crouch and erect
protected bool HasProneException()
{
return false;
}
// ACTION LOGIC -------------------------------------------------------------------
// called from actionmanager.c
void Start( ActionData action_data ) //Setup on start of action
{
action_data.m_State = UA_START;
if ( LogManager.IsActionLogEnable() )
{
Debug.ActionLog("Time stamp: " + action_data.m_Player.GetSimulationTimeStamp(), this.ToString() , "n/a", "OnStart", action_data.m_Player.ToString() );
}
OnStart(action_data);
if ( GetGame().IsServer() )
{
OnStartServer(action_data);
string soundCat = GetSoundCategory(action_data);
if (soundCat)
action_data.m_Player.SetSoundCategoryHash(soundCat.Hash());
}
else
{
OnStartClient(action_data);
}
InformPlayers(action_data.m_Player,action_data.m_Target,UA_START);
}
void End( ActionData action_data )
{
if ( action_data.m_Player )
{
OnEnd(action_data);
if ( GetGame().IsServer() )
{
OnEndServer(action_data);
}
else
{
OnEndClient(action_data);
}
action_data.m_Player.GetActionManager().OnActionEnd();
}
}
void Interrupt(ActionData action_data)
{
End(action_data);
}
void OnEndInput(ActionData action_data)
{}
void EndInput(ActionData action_data)
{
action_data.m_ReciveEndInput = true;
OnEndInput(action_data);
}
void OnEndRequest(ActionData action_data)
{}
void EndRequest(ActionData action_data)
{
OnEndRequest(action_data);
}
bool CanReceiveAction(ActionTarget target)
{
bool result = true;
PlayerBase target_player = PlayerBase.Cast(target.GetObject());
if (target_player)
{
result = !target_player.IsJumpInProgress();
result = result && !(target_player.GetCommand_Ladder() || target_player.GetCommand_Vehicle() || target_player.GetCommand_Swim());
}
return result;
}
static int ComputeConditionMask( PlayerBase player, ActionTarget target, ItemBase item )
{
int mask = 0;
if ( player.GetCommand_Vehicle() )
{
mask |= ActionConditionMask.ACM_IN_VEHICLE;
}
if ( player.GetCommand_Ladder() )
{
mask |= ActionConditionMask.ACM_ON_LADDER;
}
if ( player.IsRestrained() )
{
mask |= ActionConditionMask.ACM_RESTRAIN;
}
if ( player.GetCommand_Swim() )
{
mask |= ActionConditionMask.ACM_SWIMMING;
}
if ( player.IsRaised() )
{
mask |= ActionConditionMask.ACM_RAISED;
}
if ( player.GetCommand_Move() && player.GetCommand_Move().IsOnBack() )
{
mask |= ActionConditionMask.ACM_ON_BACK;
}
if ( player.GetThrowing().IsThrowingModeEnabled())
{
mask |= ActionConditionMask.ACM_THROWING;
}
if (player.IsLeaning())
{
mask |= ActionConditionMask.ACM_LEANING;
}
if (player.GetBrokenLegs() == eBrokenLegs.BROKEN_LEGS)
{
mask |= ActionConditionMask.ACM_BROKEN_LEGS;
}
return mask;
}
bool Can( PlayerBase player, ActionTarget target, ItemBase item, int condition_mask )
{
if ( ( (condition_mask & m_ConditionMask) != condition_mask ) || ( !IsFullBody(player) && !player.IsPlayerInStance(GetStanceMask(player)) ) || player.IsRolling() )
return false;
if ( HasTarget() )
{
if(!FirearmActionBase.Cast(this))
{
EntityAI entity = EntityAI.Cast(target.GetObject());
if ( entity && !target.GetObject().IsMan() )
{
Man man = entity.GetHierarchyRootPlayer();
if ( man && man != player )
return false;
}
}
if ( m_ConditionTarget && !m_ConditionTarget.Can(player, target))
return false;
}
if ( m_ConditionItem && !m_ConditionItem.Can(player, item))
return false;
if ( !ActionCondition(player, target, item) )
return false;
if ( IsFullBody(player) )
{
int stanceIdx = DayZPlayerUtils.ConvertStanceMaskToStanceIdx(GetStanceMask(player));
if (stanceIdx != -1 && !DayZPlayerUtils.PlayerCanChangeStance(player, stanceIdx ))
return false;
}
return true;
}
bool Can(PlayerBase player, ActionTarget target, ItemBase item)
{
int condition_mask = ComputeConditionMask(player, target, item);
return Can( player, target, item, condition_mask);
}
protected bool CanContinue( ActionData action_data )
{
if (!action_data.m_Player.IsPlayerInStance(action_data.m_PossibleStanceMask) || !m_ConditionItem || !m_ConditionItem.CanContinue(action_data.m_Player,action_data.m_MainItem) || !m_ConditionTarget || !m_ConditionTarget.CanContinue(action_data.m_Player,action_data.m_Target))
return false;
return ActionConditionContinue(action_data);
}
bool HasVariants()
{
return m_VariantManager != null;
}
int GetVariantsCount()
{
if (m_VariantManager)
return m_VariantManager.GetActionsCount();
return 0;
}
int GetVariants(out array<ref ActionBase> variants)
{
if (m_VariantManager)
return m_VariantManager.GetActions(variants);
return 0;
}
void SetVariantID(int ID)
{
m_VariantID = ID;
}
int GetVariantID()
{
return m_VariantID;
}
void UpdateVariants(Object item, Object target, int componet_index)
{
if ( m_VariantManager )
{
m_VariantManager.UpdateVariants(item, target, componet_index);
}
}
ActionVariantManager GetVariantManager()
{
if ( !m_VariantManager )
m_VariantManager = new ActionVariantManager(this.Type());
return m_VariantManager;
}
// call only on client side for lock inventory before action
// return if has successfuly reserved inventory
bool InventoryReservation(ActionData action_data)
{
if ((IsLocal() || !UseAcknowledgment()) && IsInstant())
return true;
//action_data.m_ReservedInventoryLocations = new array<ref InventoryLocation>;
bool success = true;
InventoryLocation targetInventoryLocation = NULL;
InventoryLocation handInventoryLocation = NULL;
// lock target if it has target
if (HasTarget())
{
ItemBase targetItem;
if ( ItemBase.CastTo(targetItem,action_data.m_Target.GetObject()) )
{
targetInventoryLocation = new InventoryLocation;
targetItem.GetInventory().GetCurrentInventoryLocation(targetInventoryLocation);
if ( action_data.m_Player.GetInventory().HasInventoryReservation( targetItem, targetInventoryLocation) )
{
success = false;
}
else
{
action_data.m_Player.GetInventory().AddInventoryReservationEx( targetItem, targetInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
}
}
}
handInventoryLocation = new InventoryLocation;
handInventoryLocation.SetHands(action_data.m_Player,action_data.m_Player.GetItemInHands());
if (action_data.m_Player.GetInventory().HasInventoryReservation( action_data.m_Player.GetItemInHands(), handInventoryLocation))
{
if (HasTarget())
{
action_data.m_Player.GetInventory().ClearInventoryReservation(targetItem, targetInventoryLocation);
}
success = false;
}
else
{
action_data.m_Player.GetInventory().AddInventoryReservationEx( action_data.m_Player.GetItemInHands(), handInventoryLocation, GameInventory.c_InventoryReservationTimeoutMS);
}
if (success)
{
if (targetInventoryLocation)
action_data.m_ReservedInventoryLocations.Insert(targetInventoryLocation);
if (handInventoryLocation)
action_data.m_ReservedInventoryLocations.Insert(handInventoryLocation);
}
return success;
}
void ClearInventoryReservationEx(ActionData action_data)
{
if (action_data.m_ReservedInventoryLocations)
{
InventoryLocation il;
for ( int i = 0; i < action_data.m_ReservedInventoryLocations.Count(); i++)
{
il = action_data.m_ReservedInventoryLocations.Get(i);
EntityAI entity = il.GetItem();
action_data.m_Player.GetInventory().ClearInventoryReservationEx( il.GetItem() , il );
}
action_data.m_ReservedInventoryLocations.Clear();
}
}
void RefreshReservations(ActionData action_data)
{
if (action_data.m_ReservedInventoryLocations)
{
InventoryLocation il;
for (int i = 0; i < action_data.m_ReservedInventoryLocations.Count(); i++)
{
il = action_data.m_ReservedInventoryLocations.Get(i);
EntityAI entity = il.GetItem();
action_data.m_Player.GetInventory().ExtendInventoryReservationEx(il.GetItem() , il, 10000);
}
}
}
// action need first have permission from server before can start
bool UseAcknowledgment()
{
return true;
}
//! DEPRECATED delivers message ids to clients based on given context
protected void InformPlayers( PlayerBase player, ActionTarget target, int state );
void SendMessageToClient( Object reciever, string message ) //sends given string to client, don't use if not nescessary
{
PlayerBase man;
if (GetGame().IsServer() && Class.CastTo(man, reciever) && m_MessageParam && reciever.IsAlive() && message != "")
{
m_MessageParam.param1 = message;
GetGame().RPCSingleParam(man, ERPCs.RPC_USER_ACTION_MESSAGE, m_MessageParam, true, man.GetIdentity());
}
}
// ActionCondition Rules
// ------------------------------------------------------
protected bool IsDamageDestroyed(ActionTarget target)
{
return target.GetObject() && target.GetObject().IsDamageDestroyed();
}
protected bool IsBuilding(ActionTarget target)
{
return target.GetObject() && target.GetObject().IsBuilding();
}
protected bool IsTransport(ActionTarget target)
{
return target.GetObject() && target.GetObject().IsTransport();
}
protected bool IsInReach(PlayerBase player, ActionTarget target, float maxDistance = 1.0)
{
Object obj = target.GetObject();
if (!obj)
return false;
float distanceRoot, distanceHead;
vector modelPos, worldPos, playerHeadPos;
// we're using sq distance in comparison
maxDistance = maxDistance * maxDistance;
// get position of Head bone
MiscGameplayFunctions.GetHeadBonePos(player, playerHeadPos);
array<string> componentNames = new array<string>();
obj.GetActionComponentNameList(target.GetComponentIndex(), componentNames);
foreach (string componentName : componentNames)
{
if (componentName.Contains("doorstwin"))
continue;
modelPos = obj.GetSelectionPositionMS(componentName);
worldPos = obj.ModelToWorld(modelPos);
break;
}
distanceRoot = vector.DistanceSq(worldPos, player.GetPosition());
distanceHead = vector.DistanceSq(worldPos, playerHeadPos);
return distanceRoot <= maxDistance || distanceHead <= maxDistance;
}
// ------------------------------------------------------
// SOUNDS ------------------------------------------------------
SoundOnVehicle PlayActionSound( PlayerBase player )
{
if ( GetGame().IsServer() && player )
{
if ( m_Sound != "" )
{
return GetGame().CreateSoundOnObject(player, m_Sound, 6, false);
}
else if ( m_Sounds && m_Sounds.Count() > 0 )
{
int rand_num = Math.RandomInt(0, m_Sounds.Count());
return GetGame().CreateSoundOnObject(player, m_Sounds.Get(rand_num), 6, false);
}
}
return NULL;
}
void OnActionInfoUpdate( PlayerBase player, ActionTarget target, ItemBase item )
{
}
//sound category matches with a soundtable category in config, selects correct soundset
string GetSoundCategory(ActionData action_data)
{
return "";
}
// EVENTS ------------------------------------------------
void OnUpdate(ActionData action_data)
{}
void OnUpdateClient(ActionData action_data)
{
if ( !GetGame().IsDedicatedServer() )
{
if (action_data.m_RefreshReservationTimer > 0)
{
action_data.m_RefreshReservationTimer--;
}
else
{
action_data.m_RefreshReservationTimer = m_RefreshReservationTimerValue;
RefreshReservations(action_data);
}
}
}
void OnUpdateServer(ActionData action_data)
{}
void OnStart(ActionData action_data)
{
if (action_data.m_Player != NULL && action_data.m_Player.IsPlacingLocal() && !IsDeploymentAction())
action_data.m_Player.PlacingCancelLocal();
}
void OnStartClient(ActionData action_data)
{}
void OnStartServer(ActionData action_data)
{
}
void OnEnd(ActionData action_data)
{
}
void OnEndClient(ActionData action_data)
{}
void OnEndServer(ActionData action_data)
{
}
// SOFT SKILLS ------------------------------------------------
float GetSpecialtyWeight()
{
if(m_SpecialtyWeight == 0)
{
#ifdef DEVELOPER
//Print("UserAction does not use SoftSkills");
#endif
}
return m_SpecialtyWeight;
}
int GetState( ActionData action_data )
{
return action_data.m_State;
}
float GetProgress( ActionData action_data )
{
return -1;
}
ActionInput GetInput()
{
return m_Input;
}
void SetID(int actionId)
{
m_ActionID = actionId;
}
int GetID()
{
return m_ActionID;
}
string GetAdminLogMessage(ActionData action_data)
{
return "";
}
}; |