浏览代码

Adding ReviveAction

ReviveAction brings Fainted characters back to life. ServerCharacter only allows PCs to become Fainted - NPCs become dead instead.
HP <= 0 is the triggering condition for going from Alive to either Fainted or Dead. That also clears out the action queue and prevents NPC AIBrain from being updated.
/main
sorcerer_king 3 年前
当前提交
490c45ba
共有 6 个文件被更改,包括 109 次插入11 次删除
  1. 1
      Assets/BossRoom/Scripts/Server/Game/Action/Action.cs
  2. 6
      Assets/BossRoom/Scripts/Server/Game/Action/ActionPlayer.cs
  3. 43
      Assets/BossRoom/Scripts/Server/Game/Character/ServerCharacter.cs
  4. 15
      Assets/BossRoom/Scripts/Shared/Game/Action/ActionRequestData.cs
  5. 52
      Assets/BossRoom/Scripts/Server/Game/Action/ReviveAction.cs
  6. 3
      Assets/BossRoom/Scripts/Server/Game/Action/ReviveAction.cs.meta

1
Assets/BossRoom/Scripts/Server/Game/Action/Action.cs


{
case ActionLogic.MELEE: return new MeleeAction(parent, ref data, level);
case ActionLogic.CHASE: return new ChaseAction(parent, ref data, level);
case ActionLogic.REVIVE: return new ReviveAction(parent, ref data, level);
default: throw new System.NotImplementedException();
}
}

6
Assets/BossRoom/Scripts/Server/Game/Action/ActionPlayer.cs


public void PlayAction(ref ActionRequestData data )
{
//sanity check that prevents dead or fainted characters from executing actions
if (m_parent.NetState.NetworkLifeState.Value != LifeState.ALIVE)
{
return;
}
if( !data.ShouldQueue )
{
ClearActions();

43
Assets/BossRoom/Scripts/Server/Game/Character/ServerCharacter.cs


using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <param name="data">Contains all data necessary to create the action</param>
public void PlayAction(ref ActionRequestData data )
{
this.m_actionPlayer.PlayAction(ref data);
//the character needs to be alive in order to be able to play actions
if (NetState.NetworkLifeState.Value == LifeState.ALIVE)
{
this.m_actionPlayer.PlayAction(ref data);
}
}
/// <summary>

{
//in a more complicated implementation, we might look up all sorts of effects from the inflicter, and compare them
//to our own effects, and modify the damage or healing as appropriate. But in this game, we just take it straight.
//we can't currently heal a dead character back to Alive state.
//that's handled by a separate function.
//TODO: handle death state.
GameObject.Destroy(this.gameObject);
ClearActions();
if (IsNPC)
{
NetState.NetworkLifeState.Value = LifeState.DEAD;
}
else
{
NetState.NetworkLifeState.Value = LifeState.FAINTED;
}
}
/// <summary>
/// Receive a Life State change that brings Fainted characters back to Alive state.
/// </summary>
/// <param name="inflicter">Person reviving the character.</param>
/// <param name="HP">The HP to set to a newly revived character.</param>
public void Revive(ServerCharacter inflicter, int HP)
{
if (NetState.NetworkLifeState.Value == LifeState.FAINTED)
{
NetState.HitPoints.Value = HP;
NetState.NetworkLifeState.Value = LifeState.ALIVE;
}
if (m_aiBrain != null)
if (m_aiBrain != null && NetState.NetworkLifeState.Value == LifeState.ALIVE)
{
m_aiBrain.Update();
}

15
Assets/BossRoom/Scripts/Shared/Game/Action/ActionRequestData.cs


TANK_BASEATTACK,
ARCHER_BASEATTACK,
GENERAL_CHASE,
GENERAL_REVIVE,
}

RANGED,
RANGEDTARGETED,
CHASE,
//O__O adding a new ActionLogic type? Update Action.MakeAction!
REVIVE,
//O__O adding a new ActionLogic branch? Update Action.MakeAction!
}
/// <summary>

{ActionLogic.RANGED, new ActionLogicInfo{HasDirection=true} },
{ActionLogic.RANGEDTARGETED, new ActionLogicInfo{HasTarget=true} },
{ActionLogic.CHASE, new ActionLogicInfo{HasTarget=true, HasAmount=true} },
{ActionLogic.REVIVE, new ActionLogicInfo{HasTarget=true} },
};
public static Dictionary<ActionType, List<ActionDescription>> ActionDescriptions = new Dictionary<ActionType, List<ActionDescription>>

{
{new ActionDescription{Logic=ActionLogic.CHASE } }
}
}
},
{ ActionType.GENERAL_REVIVE, new List<ActionDescription>
{
{new ActionDescription{Logic=ActionLogic.REVIVE, Amount=10, ExecTime_s=0.3f, Duration_s=0.5f, Anim="Todo" } }
}
}
};
}

52
Assets/BossRoom/Scripts/Server/Game/Action/ReviveAction.cs


using MLAPI.Spawning;
using UnityEngine;
namespace BossRoom.Server
{
public class ReviveAction : Action
{
private bool m_ExecFired;
private ServerCharacter m_TargetCharacter;
public ReviveAction(ServerCharacter parent, ref ActionRequestData data, int level) : base(parent, ref data, level)
{
}
public override bool Start()
{
if (m_Data.TargetIds == null || m_Data.TargetIds.Length == 0 || !SpawnManager.SpawnedObjects.ContainsKey(m_Data.TargetIds[0]))
{
Debug.Log("Failed to start ReviveAction. The target entity wasn't submitted or doesn't exist anymore");
return false;
}
var targetNeworkedObj = SpawnManager.SpawnedObjects[m_Data.TargetIds[0]];
m_TargetCharacter = targetNeworkedObj.GetComponent<ServerCharacter>();
m_Parent.NetState.S2C_BroadcastAction(ref Data);
return true;
}
public override bool Update()
{
if (!m_ExecFired && Time.time - TimeStarted >= Description.ExecTime_s)
{
m_ExecFired = true;
if (m_TargetCharacter.NetState.NetworkLifeState.Value == LifeState.FAINTED)
{
m_TargetCharacter.Revive(m_Parent, (int) m_Data.Amount);
}
else
{
//cancel the action if the target is alive!
Cancel();
return false;
}
}
return true;
}
}
}

3
Assets/BossRoom/Scripts/Server/Game/Action/ReviveAction.cs.meta


fileFormatVersion: 2
guid: 1122d1ad1a0b437c8a0e586ecb64449d
timeCreated: 1610045410
正在加载...
取消
保存