newzone command
Added newzone command and updated readme
This commit is contained in:
parent
e9b32dec0b
commit
588d89a5d0
12 changed files with 171 additions and 36 deletions
17
Assets/Scripts/ServerShared/Agents/AgentTask.cs
Normal file
17
Assets/Scripts/ServerShared/Agents/AgentTask.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public abstract class AgentTask
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public enum AgentJob
|
||||
{
|
||||
Mine,
|
||||
Haul,
|
||||
Tow,
|
||||
Defend,
|
||||
Attack
|
||||
}
|
||||
11
Assets/Scripts/ServerShared/Agents/AgentTask.cs.meta
Normal file
11
Assets/Scripts/ServerShared/Agents/AgentTask.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 610ba26a0be594144b79c6206a0623ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -43,11 +43,11 @@ public class VelocityMatch : AgentBehavior
|
|||
var velocity = length(_entity.Velocity);
|
||||
var deltaV = Objective.Velocity - _entity.Velocity;
|
||||
|
||||
var stoppingTime = length(deltaV) / _entity.Context.Evaluate((_thrust.Data as ThrusterData).Thrust, _thrust.Item, _entity) * _entity.Mass;
|
||||
var stoppingDistance = stoppingTime * velocity / 2;
|
||||
var stoppingTime = length(deltaV) / (_entity.Context.Evaluate((_thrust.Data as ThrusterData).Thrust, _thrust.Item, _entity) / _entity.Mass);
|
||||
var stoppingDistance = stoppingTime * (velocity / 2);
|
||||
|
||||
var angleDiff = _entity.Direction.AngleDiff(deltaV);
|
||||
var turnaroundTime = angleDiff / _entity.Context.Evaluate((_turning.Data as TurningData).Torque, _turning.Item, _entity) * _entity.Mass;
|
||||
var turnaroundTime = angleDiff / (_entity.Context.Evaluate((_turning.Data as TurningData).Torque, _turning.Item, _entity) / _entity.Mass);
|
||||
var turnaroundDistance = turnaroundTime * velocity;
|
||||
|
||||
return float2(stoppingDistance + turnaroundDistance, stoppingTime + turnaroundTime);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ public class VelocityLimitData : IBehaviorData
|
|||
}
|
||||
}
|
||||
|
||||
[UpdateOrder(100)]
|
||||
public class VelocityLimit : IBehavior
|
||||
{
|
||||
public Entity Entity { get; }
|
||||
|
|
|
|||
|
|
@ -148,9 +148,17 @@ public class StrategyGameManager : MonoBehaviour
|
|||
|
||||
void spawn(string[] args)
|
||||
{
|
||||
Debug.Log("Spawning ship!");
|
||||
if (!TestMode)
|
||||
return;
|
||||
|
||||
var zoneData = _cache.Get<ZoneData>(_populatedZone);
|
||||
|
||||
if (zoneData == null)
|
||||
{
|
||||
Debug.Log("Attempted to spawn ship but no zone is populated!");
|
||||
return;
|
||||
}
|
||||
|
||||
// Parse first argument as hull name, default to Fighter if argument missing
|
||||
HullData hullData;
|
||||
if (args.Length > 1)
|
||||
|
|
@ -213,15 +221,75 @@ public class StrategyGameManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
void newzone(string[] args)
|
||||
{
|
||||
var zoneData = _cache.Get<ZoneData>(_selectedZone);
|
||||
|
||||
if (zoneData == null)
|
||||
{
|
||||
Debug.Log("Attempted to regenerate zone but no zone is selected!");
|
||||
return;
|
||||
}
|
||||
|
||||
if(_populatedZone!=Guid.Empty)
|
||||
_context.UnloadZone(_cache.Get<ZoneData>(_populatedZone));
|
||||
_cache.Delete(zoneData);
|
||||
_galaxyResponseZones.Remove(zoneData.ID);
|
||||
|
||||
var newZone = zoneData.Copy();
|
||||
newZone.ID = Guid.NewGuid();
|
||||
newZone.Name = newZone.ID.ToString().Substring(0, 8);
|
||||
newZone.Visited = false;
|
||||
|
||||
var linkedZones = _cache.GetAll<ZoneData>().Where(z => z.Wormholes.Any(w => w == zoneData.ID)).ToArray();
|
||||
foreach (var linkedZone in linkedZones)
|
||||
{
|
||||
linkedZone.Wormholes.Remove(zoneData.ID);
|
||||
linkedZone.Wormholes.Add(newZone.ID);
|
||||
}
|
||||
newZone.Wormholes = linkedZones.Select(z => z.ID).ToList();
|
||||
|
||||
var zone = _galaxyResponseZones[newZone.ID] = new GalaxyResponseZone
|
||||
{
|
||||
Links = newZone.Wormholes.ToArray(),
|
||||
Name = newZone.Name,
|
||||
Position = newZone.Position,
|
||||
ZoneID = newZone.ID
|
||||
};
|
||||
|
||||
var galaxyZone = _galaxyZoneObjects[zoneData.ID];
|
||||
_galaxyZoneObjects.Remove(zoneData.ID);
|
||||
galaxyZone.Label.text = newZone.Name;
|
||||
_galaxyZoneObjects[newZone.ID] = galaxyZone;
|
||||
|
||||
var collider = galaxyZone.Background.GetComponent<ClickableCollider>();
|
||||
collider.Clear();
|
||||
collider.OnClick += (_, pointer) =>
|
||||
{
|
||||
if (_selectedGalaxyZone != null)
|
||||
_selectedGalaxyZone.Background.material.SetColor("_TintColor", UnselectedColor);
|
||||
if(_selectedZone != zone.ZoneID)
|
||||
CultClient.Send(new ZoneRequestMessage{ZoneID = zone.ZoneID});
|
||||
_selectedZone = zone.ZoneID;
|
||||
_selectedGalaxyZone = galaxyZone;
|
||||
_selectedGalaxyZone.Background.material.SetColor("_TintColor", SelectedColor);
|
||||
_selectedZone = zone.ZoneID;
|
||||
|
||||
// If the user double clicks on a zone, switch to the zone tab
|
||||
if(pointer.clickCount == 2) ZoneTabButton.OnPointerClick(pointer);
|
||||
};
|
||||
|
||||
_cache.Add(newZone);
|
||||
|
||||
_selectedZone = newZone.ID;
|
||||
_populatedZone = Guid.Empty;
|
||||
|
||||
if(_currentTab == ZoneTabButton)
|
||||
PopulateZone();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (TestMode)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.Space) && _currentTab == ZoneTabButton)
|
||||
{
|
||||
PopulateZone();
|
||||
}
|
||||
}
|
||||
if (_context != null)
|
||||
{
|
||||
_context.Time = Time.time;
|
||||
|
|
@ -255,6 +323,14 @@ public class StrategyGameManager : MonoBehaviour
|
|||
}
|
||||
}
|
||||
|
||||
private void OnApplicationQuit()
|
||||
{
|
||||
if (TestMode)
|
||||
{
|
||||
// TODO: Save game state on exit
|
||||
}
|
||||
}
|
||||
|
||||
void PopulateGalaxy()
|
||||
{
|
||||
_galaxyPopulated = true;
|
||||
|
|
|
|||
|
|
@ -31,14 +31,14 @@ public class ClickCatcher : MonoBehaviour, IPointerEnterHandler, IPointerExitHan
|
|||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
Debug.Log("Pointer Entered");
|
||||
//Debug.Log("Pointer Entered");
|
||||
OnEnter?.Invoke(eventData);
|
||||
PointerIsInside = true;
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
Debug.Log("Pointer Exited");
|
||||
//Debug.Log("Pointer Exited");
|
||||
OnExit?.Invoke(eventData);
|
||||
PointerIsInside = false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ public class ClickableCollider : MonoBehaviour
|
|||
|
||||
public void Click(PointerEventData eventData) => OnClick?.Invoke(this, eventData);
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
OnClick = null;
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
var proto = GetComponent<Prototype>();
|
||||
|
|
|
|||
|
|
@ -29,8 +29,8 @@ public static class UnityExtensions
|
|||
//monoList.Add();
|
||||
foreach (var component in monoList)
|
||||
{
|
||||
try
|
||||
{
|
||||
// try
|
||||
// {
|
||||
Type type = component.GetType();
|
||||
|
||||
MethodInfo method = type.GetMethod(methodName, BindingFlags.Instance |
|
||||
|
|
@ -40,15 +40,15 @@ public static class UnityExtensions
|
|||
|
||||
if(method!=null)
|
||||
method.Invoke(component, new[] { value });
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
//Re-create the Error thrown by the original SendMessage function
|
||||
if (options == SendMessageOptions.RequireReceiver)
|
||||
Debug.LogError("SendMessage " + methodName + " has no receiver!");
|
||||
|
||||
Debug.LogError(e.Message);
|
||||
}
|
||||
// }
|
||||
// catch (Exception e)
|
||||
// {
|
||||
// //Re-create the Error thrown by the original SendMessage function
|
||||
// if (options == SendMessageOptions.RequireReceiver)
|
||||
// Debug.LogError("SendMessage " + methodName + " has no receiver!");
|
||||
//
|
||||
// Debug.LogError(e.Message);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue