mirror of
https://github.com/FriendshipIsEpic/FiE-Game.git
synced 2025-02-17 10:54:22 +01:00
100 lines
2.4 KiB
C#
100 lines
2.4 KiB
C#
|
using Fie.Object;
|
||
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace Fie.AI
|
||
|
{
|
||
|
public class FieAIHateController : FieAIControllerBase
|
||
|
{
|
||
|
private float MAXIMUM_STACKED_HATE = 6f;
|
||
|
|
||
|
private Dictionary<int, IEnumerator> _hateCorutine = new Dictionary<int, IEnumerator>();
|
||
|
|
||
|
private Dictionary<int, float> _hateList = new Dictionary<int, float>();
|
||
|
|
||
|
private void Start()
|
||
|
{
|
||
|
_ownerCharacter.damageSystem.damagedEvent += delegate(FieGameCharacter attacker, FieDamage damage)
|
||
|
{
|
||
|
if (!(attacker == null) && damage != null && PhotonNetwork.isMasterClient)
|
||
|
{
|
||
|
AddHate(attacker, damage.hate);
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
private void AddHate(FieGameCharacter attaker, float hate)
|
||
|
{
|
||
|
if (!(attaker == null))
|
||
|
{
|
||
|
int instanceID = attaker.GetInstanceID();
|
||
|
if (_hateCorutine.ContainsKey(instanceID))
|
||
|
{
|
||
|
StopCoroutine(_hateCorutine[instanceID]);
|
||
|
}
|
||
|
if (!_hateList.ContainsKey(instanceID))
|
||
|
{
|
||
|
_hateList[instanceID] = hate;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
_hateList[instanceID] = Mathf.Min(_hateList[instanceID] + hate, MAXIMUM_STACKED_HATE);
|
||
|
}
|
||
|
_hateCorutine[instanceID] = CalculateHateCoroutine(instanceID);
|
||
|
StartCoroutine(_hateCorutine[instanceID]);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void Update()
|
||
|
{
|
||
|
updateLockonTargetByHate();
|
||
|
}
|
||
|
|
||
|
private void updateLockonTargetByHate()
|
||
|
{
|
||
|
if (_hateList.Count > 0)
|
||
|
{
|
||
|
bool flag = false;
|
||
|
int instanceId = 0;
|
||
|
float num = 0f;
|
||
|
foreach (KeyValuePair<int, float> hate in _hateList)
|
||
|
{
|
||
|
if (num < hate.Value)
|
||
|
{
|
||
|
instanceId = hate.Key;
|
||
|
flag = true;
|
||
|
}
|
||
|
num = Mathf.Max(num, hate.Value);
|
||
|
}
|
||
|
if (flag)
|
||
|
{
|
||
|
_ownerCharacter.detector.ChangeLockonTargetByInstanceID(instanceId);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private IEnumerator CalculateHateCoroutine(int attackerInstanceId)
|
||
|
{
|
||
|
if (_hateList.ContainsKey(attackerInstanceId))
|
||
|
{
|
||
|
Dictionary<int, float> hateList;
|
||
|
int key;
|
||
|
(hateList = _hateList)[key = attackerInstanceId] = hateList[key] - Time.deltaTime;
|
||
|
if (!(_hateList[attackerInstanceId] <= 0f))
|
||
|
{
|
||
|
yield return (object)0;
|
||
|
/*Error: Unable to find new state assignment for yield return*/;
|
||
|
}
|
||
|
_hateList.Remove(attackerInstanceId);
|
||
|
}
|
||
|
if (_hateCorutine.ContainsKey(attackerInstanceId))
|
||
|
{
|
||
|
_hateCorutine.Remove(attackerInstanceId);
|
||
|
}
|
||
|
yield return (object)null;
|
||
|
/*Error: Unable to find new state assignment for yield return*/;
|
||
|
}
|
||
|
}
|
||
|
}
|