public override string GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { foreach (var actor in world.ActorMap.GetActorsAt(cell)) { foreach (var researchActor in researchActors) { var action = ResearchUtils.GetAction(researchActor, actor); if (action == ResearchAction.None) { continue; } var info = researchActor.Info.TraitInfo <ResearchesInfo>(); if (action == ResearchAction.Start) { return(info.Cursor); } if (action == ResearchAction.Stop) { return(info.BlockedCursor); } } } return(null); }
public override string?GetCursor(World world, CPos cell, int2 worldPixel, MouseInput mi) { foreach (var actor in world.ActorMap.GetActorsAt(cell)) { foreach (var researchActor in this.researchActors) { var action = ResearchUtils.GetAction(researchActor, actor); var info = researchActor.Info.TraitInfoOrDefault <ResearchesInfo>(); switch (action) { case ResearchAction.Start: return(info.Cursor); case ResearchAction.Stop: return(info.BlockedCursor); case ResearchAction.None: break; default: throw new ArgumentOutOfRangeException(Enum.GetName(action)); } } } return(null); }
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string?cursor) { var action = ResearchUtils.GetAction(self, target); switch (action) { case ResearchAction.Start: cursor = this.cursorAllowed; return(true); case ResearchAction.Stop: cursor = this.cursorForbidden; return(true); case ResearchAction.None: cursor = null; return(false); default: throw new ArgumentOutOfRangeException(Enum.GetName(action)); } }
public override bool CanTargetActor(Actor self, Actor target, TargetModifiers modifiers, ref string cursor) { var action = ResearchUtils.GetAction(self, target); if (action == ResearchAction.Start) { cursor = cursorAllowed; return(true); } if (action == ResearchAction.Stop) { cursor = cursorForbidden; return(true); } cursor = null; return(false); }
void ITick.Tick(Actor self) { if (Researching == null) { return; } var action = ResearchUtils.GetAction(self, Researching); if (action == ResearchAction.None) { StopResearch(true); return; } var expectedRemainingCost = remainingTime == 1 ? 0 : totalCost * remainingTime / Math.Max(1, totalTime); var costThisFrame = remainingCost - expectedRemainingCost; if (costThisFrame != 0 && !playerResources.TakeCash(costThisFrame, true)) { return; } remainingCost -= costThisFrame; remainingTime -= 1; var researchable = Researching.Trait <Researchable>(); if (remainingTime == 0) { StopResearch(false); researchable.Level++; Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.CompleteNotification, self.Owner.Faction.InternalName); } else { researchable.SetProgress((totalTime - remainingTime) / (float)totalTime); } }
void IResolveOrder.ResolveOrder(Actor self, Order order) { if (order.OrderString != ResearchOrderTargeter.Id) { return; } if (order.Target.Type != TargetType.Actor || order.Target.Actor == null) { return; } var action = ResearchUtils.GetAction(self, order.Target.Actor); if (action == ResearchAction.Start) { StartResearch(order.Target.Actor); } else if (action == ResearchAction.Stop) { order.Target.Actor.Trait <Researchable>().ResearchedBy.StopResearch(true); } }
public override IEnumerable <Order> Order(World world, CPos cell, int2 worldPixel, MouseInput mi) { if (mi.Button != Game.Settings.Game.MouseButtonPreference.Action) { world.CancelInputMode(); } else { foreach (var actor in world.ActorMap.GetActorsAt(cell)) { foreach (var researchActor in this.researchActors) { var action = ResearchUtils.GetAction(researchActor, actor); if (action == ResearchAction.None) { continue; } yield return(new(ResearchOrderTargeter.Id, researchActor, Target.FromActor(actor), true)); } } } }