Grey, tall and thin, with black eyes. Eitr is armour and fuel (shield, diet, soft fall, levitation), Heimkall sends a lethal blow home at one health every 20 minutes. Caster powers from Skrid to the archon Sameining, with on-screen cooldowns. Automated base around the Ljoskjarne: drones, three constructs, crystals, Ljosgard, Prismavard. Compendium page in EN/IT/RU. README: New in block, race section, progression, station line, changelog. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
104 lines
4.7 KiB
C#
104 lines
4.7 KiB
C#
using UnityEngine;
|
|
|
|
namespace RacesOfValheim
|
|
{
|
|
/// <summary>
|
|
/// GRAFVAETTIR, the mining grenade (Alfar_Progettazione.txt sec. 9.3): unlocked at Eikthyr, thrown
|
|
/// like a grenade at a point; five drones dig the precious ores around it for two minutes and
|
|
/// vanish. The ore falls where it stands, and nothing else limits it but its cost (eitr, a little
|
|
/// stone and flint) and a five minute wait.
|
|
///
|
|
/// The thrown part is only the spawn; the digging is AlfarMiner on the drones themselves.
|
|
/// </summary>
|
|
public static class AlfarMiners
|
|
{
|
|
private static float readyAt;
|
|
|
|
public static void Tick(Player player)
|
|
{
|
|
// Nothing to tick per frame: the miners run themselves. Kept so the power loop treats
|
|
// every power the same way.
|
|
}
|
|
|
|
public static void Throw(Player player)
|
|
{
|
|
if (Time.time < readyAt) return;
|
|
|
|
Transform aim = GameCamera.instance != null ? GameCamera.instance.transform : player.transform;
|
|
Vector3 origin = aim.position;
|
|
Vector3 direction = aim.forward;
|
|
float range = AlfarPowerConfig.GrafRange.Value;
|
|
|
|
Vector3 point = origin + direction * range;
|
|
foreach (RaycastHit hit in Physics.RaycastAll(origin, direction, range, ~0, QueryTriggerInteraction.Ignore))
|
|
{
|
|
if (hit.collider.GetComponentInParent<Player>() == player) continue;
|
|
if (Vector3.Distance(origin, hit.point) < Vector3.Distance(origin, point)) point = hit.point;
|
|
}
|
|
|
|
// The price: a little eitr, a little stone, a little flint.
|
|
string stone = SharedName("Stone");
|
|
string flint = SharedName("Flint");
|
|
int needStone = AlfarPowerConfig.GrafStone.Value;
|
|
int needFlint = AlfarPowerConfig.GrafFlint.Value;
|
|
float eitr = AlfarPowerConfig.GrafEitr.Value;
|
|
|
|
Inventory inventory = player.GetInventory();
|
|
if (inventory.CountItems(stone, -1, false) < needStone || inventory.CountItems(flint, -1, false) < needFlint)
|
|
{
|
|
player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_alfar_graf_materials", needStone, needFlint));
|
|
return;
|
|
}
|
|
if (player.GetEitr() < eitr)
|
|
{
|
|
player.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_alfar_no_eitr"));
|
|
return;
|
|
}
|
|
|
|
GameObject prefab = ZNetScene.instance != null ? ZNetScene.instance.GetPrefab(AlfarDrones.MinerName) : null;
|
|
if (prefab == null)
|
|
{
|
|
Jotunn.Logger.LogWarning($"[Alfar] No '{AlfarDrones.MinerName}' in ZNetScene: the mining drones cannot be thrown.");
|
|
return;
|
|
}
|
|
|
|
inventory.RemoveItem(stone, needStone, -1, false);
|
|
inventory.RemoveItem(flint, needFlint, -1, false);
|
|
AlfarEitr.Spend(player, eitr);
|
|
readyAt = Time.time + AlfarPowerConfig.GrafCooldown.Value;
|
|
AlfarStatusEffects.ShowTimer("graf", AlfarPowerConfig.GrafCooldown.Value);
|
|
|
|
int count = AlfarPowerConfig.GrafCount.Value;
|
|
for (int i = 0; i < count; i++)
|
|
{
|
|
Vector2 offset = Random.insideUnitCircle * 1.5f;
|
|
Vector3 where = point + new Vector3(offset.x, 1.5f + i * 0.2f, offset.y);
|
|
GameObject spawned = Object.Instantiate(prefab, where, Quaternion.identity);
|
|
|
|
AlfarMiner miner = spawned.GetComponent<AlfarMiner>();
|
|
if (miner != null)
|
|
{
|
|
miner.Centre = point;
|
|
miner.Radius = AlfarPowerConfig.GrafRadius.Value;
|
|
miner.LiveSeconds = AlfarPowerConfig.GrafSeconds.Value;
|
|
}
|
|
|
|
// Tame at once so nothing flees them and they flee nothing; no anchor, no leash.
|
|
MonsterAI ai = spawned.GetComponent<MonsterAI>();
|
|
Character character = spawned.GetComponent<Character>();
|
|
if (ai != null) ai.MakeTame();
|
|
if (character != null) character.SetTamed(true);
|
|
}
|
|
|
|
AlfarFx.Spawn("fx_JotunWitch_LightningBolt_Explosion", point);
|
|
Jotunn.Logger.LogInfo($"[Alfar] Grafvaettir thrown: {count} at {point}.");
|
|
}
|
|
|
|
private static string SharedName(string prefabName)
|
|
{
|
|
GameObject prefab = ObjectDB.instance != null ? ObjectDB.instance.GetItemPrefab(prefabName) : null;
|
|
ItemDrop drop = prefab != null ? prefab.GetComponent<ItemDrop>() : null;
|
|
return drop != null ? drop.m_itemData.m_shared.m_name : prefabName;
|
|
}
|
|
}
|
|
}
|