File size: 10,672 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 |
class ActionBaseCB : HumanCommandActionCallback
{
protected ActionData m_ActionData;
protected SoundOnVehicle m_SoundObject;//object of sound playing on entity
protected bool m_Canceled;//helps prevent doubled calling of actionbase End method
protected bool m_Interrupted;//force callback to wait till action syncs its interruption
void ActionBaseCB()
{
}
int GetPossileStanceMask()
{
return m_ActionData.m_PossibleStanceMask;
}
//Command events
override void OnFinish(bool pCanceled)
{
if ( LogManager.IsActionLogEnable() )
{
if ( m_ActionData)
Debug.ActionLog("Time stamp: " + m_ActionData.m_Player.GetSimulationTimeStamp(), m_ActionData.m_Action.ToString() , "n/a", "OnFinish", m_ActionData.m_Player.ToString() );
else
Debug.ActionLog("n/a", this.ToString() , "n/a", "OnFinish", "n/a" );
}
if ( m_SoundObject )
{
GetGame().ObjectDelete(m_SoundObject);
}
if ( m_ActionData && m_ActionData.m_Player )
{
if ( pCanceled )
{
m_ActionData.m_State = m_ActionData.m_ActionComponent.Interrupt(m_ActionData);
}
AnimatedActionBase action = AnimatedActionBase.Cast(m_ActionData.m_Action);
if(action)
action.End(m_ActionData);
}
}
void SetCommand( int command_uid )
{
InternalCommand(command_uid);
}
//---------------------------------------------------------------
//Action Component handlers
void CreateActionComponent()
{
m_ActionData.m_ActionComponent = new CADummy;
}
void InitActionComponent()
{
}
void ProgressActionComponent()
{
if ( m_ActionData.m_ActionComponent )
{
m_ActionData.m_State = m_ActionData.m_ActionComponent.Execute(m_ActionData);
}
}
void EndActionComponent()
{
}
//// THIS Interrupt is use for initialize interrupt - WARNING Interrupt with parametr is used for handling interrupt
void Interrupt()
{
if ( GetGame().IsServer() )
{
if ( LogManager.IsActionLogEnable() )
{
Debug.ActionLog("n/a", this.ToString() , "n/a", "Interrupt", m_ActionData.m_Player.ToString() );
}
if ( GetGame().IsMultiplayer() )
{
DayZPlayerSyncJunctures.SendActionInterrupt(m_ActionData.m_Player);
}
}
else
{
if (ScriptInputUserData.CanStoreInputUserData())
{
ScriptInputUserData ctx = new ScriptInputUserData;
ctx.Write(INPUT_UDT_STANDARD_ACTION_END_REQUEST);
ctx.Write(DayZPlayerConstants.CMD_ACTIONINT_INTERRUPT);
ctx.Send();
}
}
m_Interrupted = true;
}
void SetActionData(ActionData action_data )
{
m_ActionData = action_data;
}
override bool IsUserActionCallback()
{
return true;
}
float GetActionComponentProgress()
{
if ( m_ActionData.m_ActionComponent )
{
return m_ActionData.m_ActionComponent.GetProgress();
}
return 0;
}
int GetActionState()
{
return m_ActionData.m_State;
}
ActionTarget GetTarget()
{
return m_ActionData.m_Target;
}
};
class AnimatedActionBase : ActionBase
{
protected int m_CommandUID; //tells which command should be used for callback
protected int m_CommandUIDProne;
protected typename m_CallbackClass; //tells which callback should be instantiated
//-----------------------------------------------------
// Action events and methods
//-----------------------------------------------------
void AnimatedActionBase()
{
// definable
m_CallbackClass = ActionBaseCB;
}
protected void OnAlternativeEndServer( PlayerBase player ) //method called when action has not met conditions in action component
{
}
protected void OnAlternativeEndClient( PlayerBase player ) //method called when action has not met conditions in action component
{
}
protected void OnInterruptServer( PlayerBase player ) //method called when action has not met conditions in action component
{
}
protected void OnInterruptClient( PlayerBase player ) //method called when action has not met conditions in action component
{
}
protected void OnExecute( ActionData action_data )
{
}
protected void OnExecuteServer( ActionData action_data )
{
}
protected void OnExecuteClient( ActionData action_data )
{
}
//TODO MW - add comment
void OnAnimationEvent( ActionData action_data )
{
if (action_data && !action_data.m_WasExecuted)
{
ActionBase action = action_data.m_Action;
if (action && ( !action.UseMainItem() || action_data.m_MainItem ) && ( !action.HasTarget() || action_data.m_Target ))
{
if ( LogManager.IsActionLogEnable() )
{
Debug.ActionLog("Time stamp: " + action_data.m_Player.GetSimulationTimeStamp(), this.ToString() , "n/a", "OnExecute", action_data.m_Player.ToString() );
}
OnExecute(action_data);
if (GetGame().IsServer())
OnExecuteServer(action_data);
else
OnExecuteClient(action_data);
action_data.m_WasExecuted = true;
action_data.m_WasActionStarted = true;
}
}
}
override bool ActionConditionContinue( ActionData action_data ) //condition for action
{
return ActionCondition(action_data.m_Player,action_data.m_Target,action_data.m_MainItem);
}
override bool ActionCondition( PlayerBase player, ActionTarget target, ItemBase item ) //condition for action
{
return true;
}
//TODO MW - add comment
protected int GetActionCommand( PlayerBase player )
{
if ( HasProneException() )
{
if ( player.IsPlayerInStance(DayZPlayerConstants.STANCEMASK_CROUCH | DayZPlayerConstants.STANCEMASK_ERECT))
return m_CommandUID;
else
return m_CommandUIDProne;
}
return m_CommandUID;
}
protected typename GetCallbackClassTypename()
{
return m_CallbackClass;
}
// if it is set to true if action have special fullbody animation for prone and additive for crouch and erect
override bool HasProneException()
{
return false;
}
//TODO MW - add comment
protected void CreateAndSetupActionCallback( ActionData action_data )
{
//Print("ActionBase.c | CreateAndSetupActionCallback | DBG ACTION CALLBACK CREATION CALLED");
ActionBaseCB callback;
if ( IsFullBody(action_data.m_Player) )
{
Class.CastTo(callback, action_data.m_Player.StartCommand_Action(GetActionCommand(action_data.m_Player),GetCallbackClassTypename(),GetStanceMask(action_data.m_Player)));
//Print("ActionBase.c | CreateAndSetupActionCallback | DBG command starter");
}
else
{
Class.CastTo(callback, action_data.m_Player.AddCommandModifier_Action(GetActionCommand(action_data.m_Player),GetCallbackClassTypename()));
//Print("ActionBase.c | CreateAndSetupActionCallback | DBG command modif starter: "+callback.ToString()+" id:"+GetActionCommand().ToString());
}
callback.SetActionData(action_data);
callback.InitActionComponent(); //jtomasik - tohle mozna patri do constructoru callbacku?
action_data.m_Callback = callback;
}
// ACTION LOGIC -------------------------------------------------------------------
// called from actionmanager.c
override void Start( ActionData action_data ) //Setup on start of action
{
super.Start( action_data );
//Debug.Log("[Action DEBUG] Start time stamp: " + action_data.m_Player.GetSimulationTimeStamp());
if( !IsInstant() )
{
CreateAndSetupActionCallback(action_data);
}
/*Debug
SendMessageToClient( player, "ActionBase.c : Start");
Print("ActionBase.c : Start");
*/
}
// THIS Interrupt is use for ACTUAL handling of intrrupt on action side - WARNING Interrupt without parametr is used for initialize interrupt
override void Interrupt( ActionData action_data )
{
if ( action_data.m_Callback )
{
action_data.m_Callback.Cancel();
}
else
{
End( action_data );
}
}
void OnJumpStart()
{
}
// called from ActionBaseCB.c
void Do( ActionData action_data, int state )
{
if ( state == UA_ERROR || !action_data.m_Callback || !action_data.m_Player || !action_data.m_ActionComponent ) //jtomasik - tohle mozna muze byt v CancelCondtion metodu callbacku?
{
#ifdef DIAG_DEVELOPER
if ( LogManager.IsActionLogEnable() )
{
Debug.ActionLog("ABRUPT CANCEL, CONDITIONS NOT MET", this.ToString() , "n/a", "Do", action_data.m_Player.ToString() );
}
#endif
if ( action_data.m_Callback && action_data.m_Player )
{
action_data.m_Callback.Interrupt();
}
else
{
Debug.ActionLog("PLAYER LOST", this.ToString() , "n/a", "Do", action_data.m_Player.ToString() );
}
}
else
{
switch ( state )
{
case UA_PROCESSING:
if ( CanContinue(action_data) )
{
action_data.m_Callback.ProgressActionComponent();
InformPlayers(action_data.m_Player, action_data.m_Target, UA_PROCESSING);
}
else
{
action_data.m_Callback.Interrupt();
InformPlayers(action_data.m_Player, action_data.m_Target, UA_CANCEL);
Do(action_data, UA_CANCEL);
}
break;
case UA_FINISHED:
InformPlayers(action_data.m_Player,action_data.m_Target,UA_FINISHED);
action_data.m_Callback.EndActionComponent();
break;
case UA_CANCEL:
InformPlayers(action_data.m_Player,action_data.m_Target,UA_CANCEL);
action_data.m_Callback.EndActionComponent();
break;
case UA_INITIALIZE:
if ( !CanContinue(action_data) )
{
action_data.m_Callback.Interrupt();
InformPlayers(action_data.m_Player, action_data.m_Target, UA_CANCEL);
Do(action_data, UA_CANCEL);
}
default:
Debug.ActionLog("Action component returned wrong value", this.ToString() , "n/a", "Do", action_data.m_Player.ToString() );
action_data.m_Callback.Interrupt();
break;
}
}
}
// called from ActionBaseCB.c
override void End( ActionData action_data )
{
if ( action_data.m_Player )
{
if ( GetGame().IsServer() )
{
OnEndServer(action_data);
action_data.m_Player.SetSoundCategoryHash(0);
}
else
{
OnEndClient(action_data);
}
OnEnd(action_data);
// Xbox Achievemnts
if ( action_data.m_WasActionStarted )
{
if ( IsEat() )
{
GetGame().GetAnalyticsClient().OnActionEat();
}
else if ( IsDrink() )
{
GetGame().GetAnalyticsClient().OnActionDrink();
}
action_data.m_WasActionStarted = false;
}
action_data.m_Player.GetActionManager().OnActionEnd();
}
else
{
if ( LogManager.IsActionLogEnable() )
{
Debug.ActionLog("Ation could not be finished right at the end", this.ToString() , "n/a", "End", action_data.m_Player.ToString() );
}
action_data.m_Callback.Interrupt();
}
}
override float GetProgress( ActionData action_data )
{
if ( action_data.m_ActionComponent )
{
return action_data.m_ActionComponent.GetProgress();
}
return 0;
}
}; |