public IEnumerator combatLoop() { while (true) { switch (turnType) { case UnitSide.PLAYER: Debug.Log("Player phase!"); foreach (MapUnit c in playerUnits) { c.EnableAction(); //Todo: enable player UI } playerController.Enable(playerUnits); while (anyHaveTurn(playerUnits)) { yield return(null); } turnType = UnitSide.ENEMY; playerController.Disable(); Debug.Log("player phase done 2"); //close player ui break; case UnitSide.ENEMY: Debug.Log("Enemy Turn!"); //Todo: replace with ui foreach (MapUnit c in enemyUnits) { c.EnableAction(); //Todo: enable enemy ai controller UI } while (anyHaveTurn(enemyUnits)) { //aiController.moveAI(); aiController.runAI(); yield return(null); } //Notify enemy ai controller that it's done turnType = UnitSide.ALLY; break; case UnitSide.ALLY: Debug.Log("Ally Turn!"); //Todo: replace with ui foreach (MapUnit c in allyUnits) { c.EnableAction(); //Todo: enable ally ai controller UI } while (anyHaveTurn(allyUnits)) { yield return(null); } //Notify ally ai controller that it's done turnType = UnitSide.PLAYER; break; } yield return(null); } }
public void Configure(UnitView viewComponent, UnitSide unitSide, float attackSpeed) { _unitView = viewComponent; _unitSide = unitSide; _attackSpeed = attackSpeed; _signalBus.Subscribe <GameStateChangeSignal>(GameStateChanged); }
public static EntityTemplate CreateCommanderUnitEntityTemplate(UnitSide side, Coordinates coords, uint rank, EntityId?superiorId, EntityId?hqId) { var template = CreateBaseUnitEntityTemplate(side, coords, UnitType.Commander); var status = template.GetComponent <CommanderStatus.Snapshot>(); if (status != null) { var s = status.Value; s.Rank = rank; template.SetComponent(s); } var team = template.GetComponent <CommanderTeam.Snapshot>(); if (team != null) { var t = team.Value; if (superiorId != null) { t.SuperiorInfo.EntityId = superiorId.Value; } if (hqId != null) { t.HqInfo.EntityId = hqId.Value; } template.SetComponent(t); } return(template); }
public void SetLinesColor(UnitSide side) { var col = ColorDictionary.GetSideColor(side); this.Renderer.startColor = col; this.Renderer.endColor = col; }
private void GetNearestSpawn(UnitSide side, SpawnType type, Coordinates coordinates, Action <Coordinates?> callBack) { if (spawnPointsDic.TryGetValue(side, out var dic) == false) { callBack(null); return; } double length = double.MaxValue; Coordinates?target = null; foreach (var kvp in dic) { if (kvp.Value.Side != side || kvp.Value.SpawnType != type) { continue; } var diff = coordinates - kvp.Value.Position; var mag = diff.SqrMagnitude(); if (mag < length) { target = kvp.Value.Position; length = mag; } } callBack(target); }
private Vector2 _position = new Vector2(5, 5); // the inital position of each piece is 5,5 , this allow the OnPositionUpdate to work correctly public Unit(Vector2 position, UnitSide side, GameObject objectPrefab) { _gameObject = GameObject.Instantiate(objectPrefab, Position, Quaternion.identity) as GameObject; Position = position; Side = side; AllUnits.Add(this); }
void SendCommand(EntityId id, UnitSide side, Vector3 vec) { this.CommandSystem.SendCommand(new StrongholdSight.SetStrategyVector.Request( id, new StrategyVector(side, FixedPointVector3.FromUnityVector(vec))) ); }
UnitInfo getNearestEnemy(UnitSide side, Vector3 pos) { UnitInfo info = null; var length = float.MaxValue; foreach (var kvp in sightDictionary) { if (kvp.Key == side || kvp.Key == UnitSide.None) { continue; } foreach (var unit in kvp.Value) { if (unit.type != UnitType.HeadQuarter) { continue; } var mag = (unit.pos - pos).sqrMagnitude; if (mag < length) { length = mag; info = unit; } } } return(info); }
uint?CheckTouch(UnitSide side, Vector3 tgtLeft, Vector3 tgtRight, Vector3[] checkCorners, uint[] ids) { if (this.HexDic == null) { return(null); } foreach (var id in ids) { if (this.HexDic.TryGetValue(id, out var hex) == false || hex.Side == side) { continue; } HexUtils.SetHexCorners(this.Origin, id, checkCorners, HexDictionary.HexEdgeLength); if (HexUtils.CheckLine(tgtRight, tgtLeft, checkCorners, HexDictionary.HexEdgeLength / 10000)) { return(id); } } return(null); }
void GetStrongholdEntity(UnitSide side, Coordinates coords, out List <EntityId> allies, out List <EntityId> enemies) { if (strongDic == null) { UpdateStrongHolds(); } allyDic.Clear(); enemyDic.Clear(); foreach (var kvp in strongDic) { var length = (kvp.Value.coords - coords).SqrMagnitude(); if (kvp.Value.side == side) { allyDic.Add(kvp.Key, length); } else { enemyDic.Add(kvp.Key, length); } } allies = allyDic.OrderBy(kvp => kvp.Value).Select(kvp => kvp.Key).ToList(); enemies = enemyDic.OrderBy(kvp => kvp.Value).Select(kvp => kvp.Key).ToList(); }
private void Virtualize(UnitSide side, Transform trans, float range, Dictionary <EntityId, SimpleUnit> dic) { dic.Clear(); var allies = getAllyUnits(side, trans.position, range, allowDead: false, GetSingleUnitTypes(UnitType.Soldier)); foreach (var u in allies) { if (!this.TryGetComponent <BaseUnitHealth.Component>(u.id, out var health) || !this.TryGetComponent <GunComponent.Component>(u.id, out var gun)) { continue; } var simple = new SimpleUnit(); var inverse = Quaternion.Inverse(trans.rotation); simple.RelativePos = (inverse * (u.pos - trans.position)).ToFixedPointVector3(); simple.RelativeRot = (u.rot * inverse).ToCompressedQuaternion(); simple.Health = health == null ? 0: health.Value.Health; // todo calc attack and range from GunComponent; //int32 attack = 5; //float attack_range = 6; dic.Add(u.id, simple); this.UpdateSystem.SendEvent(new BaseUnitStatus.ForceState.Event(new ForceStateChange(side, UnitState.Sleep)), u.id); } }
private void StartFiring(UnitView viewComponent, UnitSide ownSide) { _fireHandle = Observable.Interval(TimeSpan.FromSeconds(_attackSpeed)) .Subscribe(_ => { Fire(ownSide, viewComponent); }).AddTo(viewComponent); _isDisposed = false; }
private void Realize(UnitSide side, Transform trans, Dictionary <EntityId, SimpleUnit> dic) { var pos = trans.position; var rot = trans.rotation; foreach (var kvp in dic) { var id = kvp.Key; if (!this.TryGetComponentObject <Transform>(id, out var t) || !this.TryGetComponent <BaseUnitHealth.Component>(id, out var health)) { continue; } t.position = GetGrounded(trans.position + rot * kvp.Value.RelativePos.ToUnityVector()); t.rotation = kvp.Value.RelativeRot.ToUnityQuaternion() * rot; var diff = kvp.Value.Health - health.Value.Health; this.UpdateSystem.SendEvent(new BaseUnitHealth.HealthDiffed.Event(new HealthDiff { Diff = diff }), id); var state = health.Value.Health > 0 ? UnitState.Alive: UnitState.Dead; this.UpdateSystem.SendEvent(new BaseUnitStatus.ForceState.Event(new ForceStateChange(side, state)), id); } dic.Clear(); }
public void SetLines(UnitSide side, Vector3[] basePoints, int layerMask, int cutNumber, float fromHeight, float underHeight, float buffer) { if (basePoints == null) { return; } int count = 0; if (cutNumber < 1) { SetPoints(linePoints, basePoints, out count); } else { pointList.Clear(); Vector3 point = Vector3.zero; for (var i = 0; i < basePoints.Length; i++) { if (i == 0) { point = basePoints[i]; pointList.Add(point); } else { var end = basePoints[i]; for (int j = 1; j <= cutNumber; j++) { pointList.Add((end * j + point * (cutNumber - j)) / cutNumber); } point = end; } } SetPoints(linePoints, pointList, out count); } for (var i = 0; i < count; i++) { var p = linePoints[i]; if (Physics.Raycast(new Vector3(p.x, fromHeight, p.z), Vector3.down, out var hit, fromHeight - underHeight, layerMask:layerMask) == false) { continue; } linePoints[i] = new Vector3(p.x, hit.point.y + buffer, p.z); } var col = ColorDictionary.GetSideColor(side); this.Renderer.startColor = col; this.Renderer.endColor = col; this.Renderer.positionCount = count; this.Renderer.SetPositions(linePoints); }
public static T AddToGameObject <T>(GameObject gameObject, float damage, UnitSide target) where T : DamageSource { T result = gameObject.AddComponent <T> (); result.damage = damage; result.target = target; return(result); }
public static UnityEngine.Color GetSideColor(UnitSide side) { if (Instance.colorSettings == null) { return(UnityEngine.Color.white); } return(Instance.colorSettings.GetSideColor(side)); }
private void AffectCapture(UnitSide side, float speed, Dictionary <UnitSide, float> staminas) { if (staminas.ContainsKey(side) == false) { staminas.Add(side, 0.0f); } staminas[side] += speed; }
private void AffectCapture(UnitSide side, float speed, Dictionary <UnitSide, float> sumsDic) { if (sumsDic.ContainsKey(side) == false) { sumsDic.Add(side, 0.0f); } sumsDic[side] += speed; }
public UnityEngine.Color GetSideColor(UnitSide side) { sideType = sideType ?? typeof(UnitSide); var list = GetColorList(sideType); list = list ?? ConvertToColorList(sideType, sideColors); return(GetColor(list, (uint)side)); }
List <UnitInfo> getAllyUnits(UnitSide side, Vector3 pos) { if (sightDictionary.ContainsKey(side) == false) { return(null); } return(sightDictionary[side]); }
public void SetInfo(Vector2 pos, UnitSide side, UnitType type) { if (this.Rect != null) { this.Rect.localPosition = pos; } image.color = UIObjectDictionary.GetSideColor(side); image.sprite = UIObjectDictionary.GetUnitSprite(type); }
void UpdateSide(UnitSide side) { if (side == currentSide) { return; } currentSide = side; SetPowers(powerReader.Data.SidePowers); SetLandLine(this.Origin, side, powerReader.Data.SidePowers); }
public float[] GetUnitSize(UnitSide unitSide) { if (unitSide == UnitSide.SideA) { return(GuildAList.Select(unit => unit.Size).ToArray()); } else { return(GuildBList.Select(unit => unit.Size).ToArray()); } }
public Transform[] GetUnitTransforms(UnitSide unitSide) { if (unitSide == UnitSide.SideA) { return(GuildAList.Select(unit => unit.Transform).ToArray()); } else { return(GuildBList.Select(unit => unit.Transform).ToArray()); } }
public float3[] GetGuildPositions(UnitSide unitSide) { if (unitSide == UnitSide.SideA) { return(GuildAList.Select(unit => unit.Position).ToArray()); } else { return(GuildBList.Select(unit => unit.Position).ToArray()); } }
public float[] GetUnitMovementSpeed(UnitSide unitSide) { if (unitSide == UnitSide.SideA) { return(GuildAList.Select(unit => unit.MovementSpeed).ToArray()); } else { return(GuildBList.Select(unit => unit.MovementSpeed).ToArray()); } }
public void RequestGetNearestSpawn(UnitSide side, SpawnType type, Coordinates coordinates, Action <Coordinates?> callBack) { if (spawnPointsDic.Count == 0) { OnQueriedEvent += () => GetNearestSpawn(side, type, coordinates, callBack); SendEntityQuery(); } else { GetNearestSpawn(side, type, coordinates, callBack); } }
private void Fire(UnitSide ownSide, UnitView view) { if (Physics.Raycast(view.Position, view.Transform.forward, out var hit, _gameSettings.WeaponRange, Constants.Constants.UnitLayer)) { _signalBus.Fire(new UnitHitSignal { OwnSide = ownSide, UnitId = hit.collider.gameObject.GetInstanceID() }); } }
public void SetHexInfo(UnitSide side, uint index, HexAttribute attribute) { if (hex) { hex.hexIndex = index; hex.attribute = attribute; } foreach (var u in units) { u.side = side; } }
public Vector3 GetRotation(UnitSide unitSide) { switch (unitSide) { case UnitSide.SideA: return(_gameSettings.GuildPositionA.Rotation); case UnitSide.SideB: return(_gameSettings.GuildPositionB.Rotation); } return(Vector3.zero); }
public Node2[] this[UnitSide side] { get { return connections [(int)side]; } }
public List<UnitCore> GetUnitListOfOppositeSide( UnitSide side ) { return side == UnitSide.Side01? side02 : side01; }