2026-06-13 04:56:50 +01:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2020-12-22 03:13:43 +00:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
|
|
|
|
|
|
|
|
using System;
|
2020-04-09 10:33:16 +01:00
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
using static Unity.Mathematics.math;
|
|
|
|
|
using static Unity.Mathematics.noise;
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public abstract class Behavior
|
2020-04-09 10:33:16 +01:00
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
public BehaviorData Data { get; }
|
|
|
|
|
public EquippedItem Item { get; }
|
|
|
|
|
private ConsumableItemEffect Consumable { get; }
|
|
|
|
|
protected ItemManager ItemManager { get; }
|
|
|
|
|
|
|
|
|
|
protected Entity Entity => Item?.Entity ?? Consumable.Entity;
|
|
|
|
|
public float Temperature => Item?.Temperature ?? Consumable.Entity.MaxTemp;
|
|
|
|
|
|
|
|
|
|
public float3 Direction
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if(Item != null)
|
|
|
|
|
{
|
|
|
|
|
var hardpoint = Entity.Hardpoints[Item.Position.x, Item.Position.y];
|
2026-06-13 16:31:45 +01:00
|
|
|
if (hardpoint != null && Entity.HardpointTransforms.TryGetValue(hardpoint, out var hardpointTransform))
|
2021-04-18 05:13:20 +01:00
|
|
|
{
|
2026-06-13 16:31:45 +01:00
|
|
|
return normalize(hardpointTransform.direction);
|
2021-04-18 05:13:20 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var itemDirection = Entity.Direction.Rotate(Item.EquippableItem.Rotation);
|
|
|
|
|
return float3(itemDirection.x, 0, itemDirection.y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return float3(Entity.Direction.x, 0, Entity.Direction.y);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected Behavior(BehaviorData data, EquippedItem item)
|
|
|
|
|
{
|
|
|
|
|
Data = data;
|
|
|
|
|
Item = item;
|
|
|
|
|
ItemManager = Item.ItemManager;
|
|
|
|
|
}
|
2026-06-13 04:56:50 +01:00
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
protected Behavior(BehaviorData data, ConsumableItemEffect consumable)
|
|
|
|
|
{
|
|
|
|
|
Data = data;
|
|
|
|
|
Consumable = consumable;
|
|
|
|
|
ItemManager = consumable.Entity.ItemManager;
|
|
|
|
|
}
|
2026-06-13 04:56:50 +01:00
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public float Evaluate(PerformanceStat stat) => Item?.Evaluate(stat) ?? Consumable.Evaluate(stat);
|
|
|
|
|
protected void AddHeat(float heat) => Item?.AddHeat(heat); // TODO: Heat for Consumables
|
|
|
|
|
|
|
|
|
|
protected void CauseDamage(float damage)
|
|
|
|
|
{
|
|
|
|
|
if (Item != null)
|
|
|
|
|
{
|
|
|
|
|
Item.EquippableItem.Durability -= damage;
|
|
|
|
|
Entity.ItemDamage.OnNext((Item, damage));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Consumable.Entity.Hull.Durability -= damage;
|
|
|
|
|
Consumable.Entity.HullDamage.OnNext(damage);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected void CauseWearDamage(float multiplier)
|
|
|
|
|
{
|
|
|
|
|
if (Item != null)
|
|
|
|
|
{
|
|
|
|
|
CauseDamage(Item.Wear * multiplier);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-13 04:56:50 +01:00
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public virtual bool Execute(float dt)
|
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2020-04-09 10:33:16 +01:00
|
|
|
}
|
|
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public interface IActivatedBehavior
|
2021-01-25 05:53:36 +00:00
|
|
|
{
|
|
|
|
|
void Activate();
|
|
|
|
|
void Deactivate();
|
|
|
|
|
}
|
2020-04-09 10:33:16 +01:00
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public interface IAnalogBehavior
|
2020-04-09 10:33:16 +01:00
|
|
|
{
|
2020-06-05 04:16:33 +01:00
|
|
|
float Axis { get; set; }
|
2020-04-09 10:33:16 +01:00
|
|
|
}
|
|
|
|
|
|
2021-03-21 01:55:25 +00:00
|
|
|
public interface IEventBehavior
|
|
|
|
|
{
|
|
|
|
|
void ResetEvents();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
public interface IInitializableBehavior
|
|
|
|
|
{
|
|
|
|
|
void Initialize();
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-25 05:53:36 +00:00
|
|
|
public interface IInteractiveBehavior
|
|
|
|
|
{
|
|
|
|
|
bool Exposed { get; }
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 01:42:13 +01:00
|
|
|
public interface IAlwaysUpdatedBehavior
|
|
|
|
|
{
|
2021-01-10 03:59:47 +00:00
|
|
|
void Update(float delta);
|
2020-05-12 01:42:13 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-31 19:53:16 +00:00
|
|
|
public interface IProgressBehavior
|
|
|
|
|
{
|
|
|
|
|
float Progress { get; }
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-10 23:20:38 +00:00
|
|
|
public interface IOrderedBehavior
|
|
|
|
|
{
|
|
|
|
|
int Order { get; }
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-28 01:50:50 +01:00
|
|
|
public interface IPersistentBehavior//<T> where T : IBehavior
|
|
|
|
|
{
|
2020-04-30 02:54:31 +01:00
|
|
|
PersistentBehaviorData Store();
|
|
|
|
|
void Restore(PersistentBehaviorData data);
|
2020-04-28 01:50:50 +01:00
|
|
|
}
|
2020-05-06 04:56:36 +01:00
|
|
|
|
2020-06-08 01:01:33 +01:00
|
|
|
public interface IPopulationAssignment
|
|
|
|
|
{
|
|
|
|
|
int AssignedPopulation { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-06 04:56:36 +01:00
|
|
|
public abstract class PersistentBehaviorData
|
|
|
|
|
{
|
|
|
|
|
}
|
2020-04-28 01:50:50 +01:00
|
|
|
|
2026-06-13 14:51:01 +01:00
|
|
|
[Inspectable]
|
2020-05-06 04:56:36 +01:00
|
|
|
public abstract class BehaviorData
|
2020-04-09 10:33:16 +01:00
|
|
|
{
|
2026-06-13 21:19:53 +01:00
|
|
|
[Inspectable, LegacyPayloadKey(0)]
|
2020-05-11 01:17:10 +01:00
|
|
|
public int Group;
|
2026-06-13 04:56:50 +01:00
|
|
|
|
2021-04-18 05:13:20 +01:00
|
|
|
public abstract Behavior CreateInstance(EquippedItem item);
|
|
|
|
|
public abstract Behavior CreateInstance(ConsumableItemEffect consumable);
|
2020-12-12 00:02:00 +00:00
|
|
|
|
|
|
|
|
public override string ToString()
|
|
|
|
|
{
|
2021-04-18 05:13:20 +01:00
|
|
|
return base.ToString().FormatTypeName();
|
2020-12-12 00:02:00 +00:00
|
|
|
}
|
2026-06-13 14:51:01 +01:00
|
|
|
}
|