implement Surrender state

This commit is contained in:
in0finite 2022-01-02 21:52:31 +01:00
parent d7b0329291
commit 6a4dbf12ef
7 changed files with 107 additions and 7 deletions

View file

@ -31,6 +31,7 @@ GameObject:
- component: {fileID: 114293662543306134}
- component: {fileID: 7181738364298022858}
- component: {fileID: 2421064630445689714}
- component: {fileID: 986117917908478283}
m_Layer: 11
m_Name: States
m_TagString: Untagged
@ -330,6 +331,18 @@ MonoBehaviour:
timeUntilAbleToEnterState: 0.5
timeUntilAbleToExitState: 0.5
timeUntilAbleToChangeAnim: 0.5
--- !u!114 &986117917908478283
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1154474390377672}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 751a2e3fa7025a3448157779e2c99fe5, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1 &1273918895060814
GameObject:
m_ObjectHideFlags: 0

View file

@ -662,6 +662,12 @@ namespace SanAndreasUnity.Behaviours
this.CurrentState.OnFlyThroughButtonPressed ();
}
public void OnSurrenderButtonPressed()
{
if (this.CurrentState != null)
this.CurrentState.OnSurrenderButtonPressed();
}
internal void OnStartCollidingWithEnex(EntranceExitMapObject enex)
{

View file

@ -40,12 +40,8 @@ namespace SanAndreasUnity.Behaviours.Peds.States
protected virtual void SwitchToMovementState()
{
System.Type type = BaseMovementState.GetMovementStateToSwitchToBasedOnInput(m_ped);
var state = (BaseMovementState) m_ped.GetStateOrLogError(type);
if (!EnoughTimePassedToSwitchBetweenMovementStates(this, state))
return;
m_ped.SwitchState(type);
this.SwitchToMovementStateIfEnoughTimePassed(type);
}
public static bool EnoughTimePassedToSwitchBetweenMovementStates(
@ -61,6 +57,18 @@ namespace SanAndreasUnity.Behaviours.Peds.States
return true;
}
public bool SwitchToMovementStateIfEnoughTimePassed(System.Type type)
{
var state = (BaseMovementState)m_ped.GetStateOrLogError(type);
if (!EnoughTimePassedToSwitchBetweenMovementStates(this, state))
return false;
m_ped.SwitchState(type);
return true;
}
public static void SwitchToMovementStateBasedOnInput (Ped ped)
{
System.Type type = GetMovementStateToSwitchToBasedOnInput(ped);
@ -161,6 +169,14 @@ namespace SanAndreasUnity.Behaviours.Peds.States
m_ped.GetStateOrLogError<FlyState> ().EnterState (true);
}
public override void OnSurrenderButtonPressed()
{
if (m_isServer)
this.SwitchToMovementStateIfEnoughTimePassed(typeof(SurrenderState));
else
base.OnSurrenderButtonPressed();
}
}
}

View file

@ -286,6 +286,11 @@ namespace SanAndreasUnity.Behaviours.Peds.States
}
public virtual void OnSurrenderButtonPressed()
{
}
public virtual void OnSwitchedStateByServer(byte[] data)
{

View file

@ -0,0 +1,47 @@
using SanAndreasUnity.Importing.Animation;
namespace SanAndreasUnity.Behaviours.Peds.States
{
public class SurrenderState : BaseMovementState
{
public override AnimId movementAnim => new AnimId("ped", "handsup");
public override AnimId movementWeaponAnim => this.movementAnim;
protected override void SwitchToMovementState()
{
// prevent switching to Stand state
System.Type type = BaseMovementState.GetMovementStateToSwitchToBasedOnInput(m_ped);
if (typeof(StandState).IsAssignableFrom(type))
return;
base.SwitchToMovementState();
}
protected override void UpdateAnims()
{
base.UpdateAnims();
if (!this.IsActiveState)
return;
if (m_model.LastAnimState != null)
m_model.LastAnimState.wrapMode = UnityEngine.WrapMode.ClampForever;
}
public override void OnSurrenderButtonPressed()
{
if (m_isServer)
this.SwitchToMovementStateIfEnoughTimePassed(typeof(StandState));
else
base.OnSurrenderButtonPressed();
}
}
public static class SurrenderStatePedExtensions
{
public static bool IsSurrendering(this Ped ped) => ped.CurrentState is SurrenderState;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 751a2e3fa7025a3448157779e2c99fe5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -1,3 +1,4 @@
using SanAndreasUnity.Behaviours.Peds.States;
using SanAndreasUnity.Importing.Items.Definitions;
using SanAndreasUnity.Importing.Paths;
using SanAndreasUnity.Utilities;
@ -60,8 +61,9 @@ namespace SanAndreasUnity.Behaviours.Peds.AI
if (this.IsSurrendering)
{
// TODO: set Surrendering button to on
// make sure ped is surrendering
if (!_ped.IsSurrendering())
_ped.OnSurrenderButtonPressed();
return;
}