private void UpdateCooldown(ActivateComponent weapon, int cooldown) { // update cooldown weapon.CurrentCooldown = cooldown; List <Part> group = Groups[weapon.Group]; int minCooldown = weapon.CurrentCooldown; int currIndex = _nextWeapon[weapon.Group]; int index = currIndex; for (int i = 0; i < group.Count; i++) { Part p = group[i]; p.Get <ActivateComponent>().MatchSome(w => { if ((w.CurrentCooldown < minCooldown) || (w.CurrentCooldown == minCooldown && IndexDist(i, currIndex, group.Count) < IndexDist(index, currIndex, group.Count))) { minCooldown = w.CurrentCooldown; index = i; } }); } _nextWeapon[weapon.Group] = index; }
private Option <ICommand> BuildFireCommand(Mech m, Part p, ActivateComponent ac, IEnumerable <Loc> targets) { p.Get <HeatComponent>().MatchSome(hc => m.UpdateHeat(hc.HeatGenerated)); return(p.Get <AmmoComponent>().Match(some: ammo => { if (ammo.Loaded > 1) { ammo.Loaded--; UpdateCooldown(ac, ac.Cooldown); return Option.Some(ac.Activate(m, targets)); } else { int rounds = Math.Min(ammo.Capacity, ammo.Remaining); ammo.Loaded = rounds; ammo.Remaining -= rounds; // use the cooldown instead of the usual one UpdateCooldown(ac, ammo.Reload); return Option.Some <ICommand>(new Commands.WaitCommand(120)); } }, none: () => { UpdateCooldown(ac, ac.Cooldown); return Option.Some(ac.Activate(m, targets)); })); }
internal Option <ICommand> AiFireMethod(Mech m, Part p, ActivateComponent ac) { foreach (var loc in ac.Target.GetAllValidTargets(m.Pos, m.Facing, Measure.Euclidean, true)) { if (loc == Game.Player.Pos) { var targets = ac.Target.GetTilesInRange(m.Pos, loc, Measure.Euclidean); return(BuildFireCommand(m, p, ac, targets)); } } return(Option.None <ICommand>()); }
private Option <ICommand> PlayerFireMethod(Mech m, Part p, ActivateComponent ac) { Game.StateHandler.PushState(new TargettingState(Game.MapHandler, m, Measure.Euclidean, ac.Target, targets => { Game.StateHandler.PopState(); Game.MessagePanel.Add($"[color=info]Info[/color]: {p.Name} fired"); return(BuildFireCommand(m, p, ac, targets)); })); return(Option.None <ICommand>()); }
void Start() { movingDirection = transform.up; activateComponent = GetComponent <ActivateComponent>(); }