Initial commit
This commit is contained in:
commit
c4a24c9fdf
142 changed files with 15491 additions and 0 deletions
159
JotunnModStub/Aswid/AswidThrall.cs
Normal file
159
JotunnModStub/Aswid/AswidThrall.cs
Normal file
|
|
@ -0,0 +1,159 @@
|
|||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
namespace RacesOfValheim
|
||||
{
|
||||
public class AswidThrall : MonoBehaviour, Interactable, Hoverable
|
||||
{
|
||||
private Character m_character;
|
||||
private MonsterAI m_ai;
|
||||
private ZNetView m_nview;
|
||||
private bool m_wasEnslaved = false;
|
||||
private bool m_wasConsumed = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
m_character = GetComponent<Character>();
|
||||
m_ai = GetComponent<MonsterAI>();
|
||||
m_nview = GetComponent<ZNetView>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (m_nview == null || !m_nview.IsValid()) return;
|
||||
|
||||
bool isEnslaved = m_nview.GetZDO().GetBool("AswidEnslaved", false);
|
||||
if (isEnslaved)
|
||||
{
|
||||
if (!m_wasEnslaved)
|
||||
{
|
||||
m_wasEnslaved = true;
|
||||
m_character.SetTamed(true); // Ensure tamed is true on client side if it missed the RPC
|
||||
|
||||
if (m_ai != null)
|
||||
{
|
||||
// Custom AI behaviors can be set here if needed
|
||||
}
|
||||
}
|
||||
|
||||
// If it dies, the local player who owns it tries to consume it
|
||||
if (m_character.IsDead() && !m_wasConsumed)
|
||||
{
|
||||
m_wasConsumed = true;
|
||||
if (m_nview.IsOwner() && AswidRace.IsAswid())
|
||||
{
|
||||
AswidRace.TryConsumeMob(m_character, m_character.GetMaxHealth());
|
||||
}
|
||||
}
|
||||
|
||||
// Only the ZDO owner should track lifetime to kill it
|
||||
if (m_nview.IsOwner())
|
||||
{
|
||||
long enslaveTime = m_nview.GetZDO().GetLong("AswidEnslaveTime", 0);
|
||||
if (enslaveTime > 0)
|
||||
{
|
||||
DateTime time = new DateTime(enslaveTime);
|
||||
if ((DateTime.Now - time).TotalSeconds >= 60.0)
|
||||
{
|
||||
// Time's up! Kill the thrall.
|
||||
HitData hit = new HitData();
|
||||
hit.m_damage.m_damage = 99999f;
|
||||
hit.m_hitType = HitData.HitType.Undefined;
|
||||
m_character.ApplyDamage(hit, true, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool Interact(Humanoid user, bool hold, bool alt)
|
||||
{
|
||||
if (hold || alt) return false;
|
||||
if (m_nview == null || !m_nview.IsValid()) return false;
|
||||
if (user != Player.m_localPlayer || !AswidRace.IsAswid()) return false;
|
||||
|
||||
bool isEnslaved = m_nview.GetZDO().GetBool("AswidEnslaved", false);
|
||||
if (isEnslaved)
|
||||
{
|
||||
// Toggle follow/stay
|
||||
if (m_ai != null)
|
||||
{
|
||||
if (m_ai.GetFollowTarget() == user.gameObject)
|
||||
{
|
||||
m_ai.SetFollowTarget(null);
|
||||
user.Message(MessageHud.MessageType.Center, $"{m_character.m_name} is staying.");
|
||||
}
|
||||
else
|
||||
{
|
||||
m_ai.SetFollowTarget(user.gameObject);
|
||||
user.Message(MessageHud.MessageType.Center, $"{m_character.m_name} is following.");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Enslave action
|
||||
if (BossProgressionManager.GetCurrentProgressionState() < 6) return false;
|
||||
|
||||
float cooldown = AswidRace.GetEnslaveCooldown();
|
||||
if (cooldown > 0)
|
||||
{
|
||||
user.Message(MessageHud.MessageType.Center, $"Dominate on cooldown ({Mathf.CeilToInt(cooldown / 60f)}m {Mathf.CeilToInt(cooldown % 60f)}s)");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Enslave it!
|
||||
AswidRace.StartEnslaveCooldown();
|
||||
|
||||
// Take ownership to set ZDO vars reliably
|
||||
m_nview.ClaimOwnership();
|
||||
|
||||
m_nview.GetZDO().Set("AswidEnslaved", true);
|
||||
m_nview.GetZDO().Set("AswidEnslaveTime", DateTime.Now.Ticks);
|
||||
m_character.SetTamed(true);
|
||||
|
||||
if (m_ai != null)
|
||||
{
|
||||
m_ai.SetFollowTarget(user.gameObject);
|
||||
}
|
||||
|
||||
GameObject vfx = ZNetScene.instance.GetPrefab("vfx_surtling_death");
|
||||
if (vfx) Instantiate(vfx, m_character.transform.position, Quaternion.identity);
|
||||
|
||||
user.Message(MessageHud.MessageType.Center, $"{m_character.m_name} dominated!");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool UseItem(Humanoid user, ItemDrop.ItemData item)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public string GetHoverText()
|
||||
{
|
||||
if (m_nview == null || !m_nview.IsValid()) return "";
|
||||
if (Player.m_localPlayer == null || !AswidRace.IsAswid()) return "";
|
||||
|
||||
bool isEnslaved = m_nview.GetZDO().GetBool("AswidEnslaved", false);
|
||||
if (isEnslaved)
|
||||
{
|
||||
bool following = m_ai != null && m_ai.GetFollowTarget() != null;
|
||||
return following ? "[<color=yellow><b>E</b></color>] Stay" : "[<color=yellow><b>E</b></color>] Follow";
|
||||
}
|
||||
else
|
||||
{
|
||||
if (BossProgressionManager.GetCurrentProgressionState() < 6) return "";
|
||||
|
||||
float cd = AswidRace.GetEnslaveCooldown();
|
||||
if (cd > 0) return $"[<color=red>E</color>] Dominate (Cooldown: {Mathf.CeilToInt(cd / 60f)}m)";
|
||||
return "[<color=yellow><b>E</b></color>] Dominate";
|
||||
}
|
||||
}
|
||||
|
||||
public string GetHoverName()
|
||||
{
|
||||
return ""; // Character component already provides the name
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue