void ITick.Tick(Actor self) { if (amtAwaitingPurification >= Info.MinAmount) { var cash = Util.ApplyPercentageModifiers(amtAwaitingPurification, modifier); playerResources.GiveCash(cash); if (Info.ShowTicks && self.Info.HasTraitInfo <IOccupySpaceInfo>()) { currentDisplayValue += cash; } amtAwaitingPurification = 0; } if (currentDisplayValue > 0 && --currentDisplayTick <= 0) { var temp = currentDisplayValue; if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(temp), Info.TickLifetime))); } currentDisplayTick = Info.TickRate; currentDisplayValue = 0; } }
void ITick.Tick(Actor self) { // Harvester was killed while unloading if (dockedHarv != null && dockedHarv.IsDead) { dockedHarv = null; } if (info.ShowTicks && currentDisplayValue > 0 && --currentDisplayTick <= 0) { var temp = currentDisplayValue; if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(temp), 30))); } currentDisplayTick = info.TickRate; currentDisplayValue = 0; } }
public override bool Tick(Actor self) { var sellValue = self.GetSellValue(); // Cast to long to avoid overflow when multiplying by the health var hp = health != null ? (long)health.HP : 1L; var maxHP = health != null ? (long)health.MaxHP : 1L; var refund = (int)((sellValue * sellableInfo.RefundPercent * hp) / (100 * maxHP)); refund = playerResources.ChangeCash(refund); foreach (var ns in self.TraitsImplementing <INotifySold>()) { ns.Sold(self); } if (showTicks && refund > 0 && self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(refund), 30))); } Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", sellableInfo.Notification, self.Owner.Faction.InternalName); self.Dispose(); return(false); }
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) { if (IsTraitDisabled || !IsValidCaptor(captor)) { return; } var resources = newOwner.PlayerActor.Trait <PlayerResources>(); var amount = resources.ChangeCash(info.Amount); if (!info.ShowTicks && amount != 0) { return; } self.World.AddFrameEndTask(w => w.Add( new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), info.DisplayDuration))); }
void AddCashTick(Actor self, int amount) { self.World.AddFrameEndTask(w => w.Add( new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(amount), info.DisplayDuration))); }
void MaybeAddCashTick(Actor self, int amount) { if (Info.ShowTicks) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), 30))); } }
public override Activity Tick(Actor self) { var sellValue = self.GetSellValue(); // Cast to long to avoid overflow when multiplying by the health var hp = health != null ? (long)health.HP : 1L; var maxHP = health != null ? (long)health.MaxHP : 1L; var refund = (int)((sellValue * sellableInfo.RefundPercent * hp) / (100 * maxHP)); playerResources.GiveCash(refund); foreach (var ns in self.TraitsImplementing <INotifySold>()) { ns.Sold(self); } if (showTicks && refund > 0 && self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(refund), 30))); } self.Dispose(); return(this); }
void ICrushResource.CrushResource(Actor self, CPos cell) { if (resourceValue == 0) { return; } var resourceAmount = resourceLayer.RemoveResource(Info.ResourceType, cell, int.MaxValue); if (resourceAmount == 0) { return; } var value = Util.ApplyPercentageModifiers(resourceValue * resourceAmount, new int[] { Info.ValueModifier }); playerResources.ChangeCash(value); if (Info.ShowTicks && self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(value), Info.TickLifetime))); } if (Info.NotifyOtherActors) { foreach (var notify in self.World.ActorsWithTrait <INotifyResourceAccepted>()) { if (notify.Actor.Owner != self.Owner) { continue; } notify.Trait.OnResourceAccepted(notify.Actor, self, Info.ResourceType, resourceAmount, resourceValue); } } }
public override Activity Tick(Actor self) { var cost = self.GetSellValue(); var refund = (cost * sellableInfo.RefundPercent * (health == null ? 1 : health.HP)) / (100 * (health == null ? 1 : health.MaxHP)); playerResources.GiveCash(refund); foreach (var ns in self.TraitsImplementing <INotifySold>()) { ns.Sold(self); } if (refund > 0 && self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(refund), 30))); } self.Dispose(); return(this); }
void INotifyKilled.Killed(Actor self, AttackInfo e) { if (e.Attacker == null || e.Attacker.Disposed) { return; } if (!info.ValidStances.HasStance(e.Attacker.Owner.Stances[self.Owner])) { return; } if (info.DeathTypes.Count > 0 && !e.Damage.DamageTypes.Overlaps(info.DeathTypes)) { return; } var displayedBounty = GetDisplayedBountyValue(self); if (info.ShowBounty && self.IsInWorld && displayedBounty > 0 && e.Attacker.Owner.IsAlliedWith(self.World.RenderPlayer)) { e.Attacker.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, FloatingText.FormatCashTick(displayedBounty), 30))); } e.Attacker.Owner.PlayerActor.Trait <PlayerResources>().GiveCash(GetBountyValue(self)); }
protected override void OnInside(Actor self) { if (target.IsDead) { return; } target.Owner.PlayerActor.Trait <PlayerResources>().GiveCash(payload); var exp = self.Owner.PlayerActor.TraitOrDefault <PlayerExperience>(); if (exp != null && target.Owner != self.Owner) { exp.GiveExperience(experience); } if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(target.CenterPosition, target.Owner.Color.RGB, FloatingText.FormatCashTick(payload), 30))); } foreach (var nct in target.TraitsImplementing <INotifyCashTransfer>()) { nct.OnAcceptingCash(target, self); } foreach (var nct in self.TraitsImplementing <INotifyCashTransfer>()) { nct.OnDeliveringCash(self, target); } }
void CollectCash() { var cash = 0; foreach (var trait in collectables) { if (!trait.IsTraitDisabled) { cash += trait.Info.Value; } } if (Info.ShowTicks && self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(cash), 30))); } self.Owner.PlayerActor.Trait <PlayerResources>().GiveCash(cash); }
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner) { if (IsTraitDisabled) { return; } var resources = newOwner.PlayerActor.Trait <PlayerResources>(); var amount = info.Amount; if (amount < 0) { // Check whether the amount of cash to be removed would exceed available player cash, in that case only remove all the player cash amount = Math.Min(resources.Cash + resources.Resources, -amount); resources.TakeCash(amount); // For correct cash tick display amount = -amount; } else { resources.GiveCash(amount); } if (!info.ShowTicks) { return; } self.World.AddFrameEndTask(w => w.Add( new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(amount), info.DisplayDuration))); }
public void Killed(Actor self, AttackInfo e) { var info = self.Info.Traits.Get <GivesBountyInfo>(); if (e.Attacker == null || e.Attacker.Destroyed) { return; } if (!info.Stances.Contains(e.Attacker.Owner.Stances[self.Owner])) { return; } var cost = self.GetSellValue(); // 2 hundreds because of GetMultiplier and info.Percentage. var bounty = cost * GetMultiplier(self) * info.Percentage / 10000; if (bounty > 0 && e.Attacker.Owner.IsAlliedWith(self.World.RenderPlayer)) { e.Attacker.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color.RGB, FloatingText.FormatCashTick(bounty), 30))); } e.Attacker.Owner.PlayerActor.Trait <PlayerResources>().GiveCash(bounty); }
public override void Activate(Actor self, Order order, SupportPowerManager manager) { base.Activate(self, order, manager); var ownResources = self.Owner.PlayerActor.Trait <PlayerResources>(); Game.Sound.Play(SoundType.World, info.OnFireSound, order.Target.CenterPosition); foreach (var a in UnitsInRange(self.World.Map.CellContaining(order.Target.CenterPosition))) { var enemyResources = a.Owner.PlayerActor.Trait <PlayerResources>(); var toTake = Math.Min(info.Maximum, (enemyResources.Cash + enemyResources.Resources) * info.Percentage / 100); var toGive = Math.Max(toTake, info.Minimum); enemyResources.TakeCash(toTake); ownResources.GiveCash(toGive); if (info.Notification != null) { Game.Sound.PlayNotification(a.World.Map.Rules, a.Owner, "Speech", info.Notification, a.Owner.Faction.InternalName); } if (info.ShowTicks) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(a.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(toGive), 30))); } } }
protected override void OnInside(Actor self) { if (target.IsDead) { return; } target.Owner.PlayerActor.Trait <PlayerResources>().GiveCash(payload); self.Destroy(); if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(target.CenterPosition, target.Owner.Color.RGB, FloatingText.FormatCashTick(payload), 30))); } }
void INotifyKilled.Killed(Actor self, AttackInfo e) { if (e.Attacker == null || e.Attacker.Disposed || IsTraitDisabled) { return; } if (!Info.ValidRelationships.HasRelationship(e.Attacker.Owner.RelationshipWith(self.Owner))) { return; } if (!Info.DeathTypes.IsEmpty && !e.Damage.DamageTypes.Overlaps(Info.DeathTypes)) { return; } var displayedBounty = GetDisplayedBountyValue(self); if (Info.ShowBounty && self.IsInWorld && displayedBounty != 0 && e.Attacker.Owner.IsAlliedWith(self.World.RenderPlayer)) { e.Attacker.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, e.Attacker.Owner.Color, FloatingText.FormatCashTick(displayedBounty), 30))); } e.Attacker.Owner.PlayerActor.Trait <PlayerResources>().ChangeCash(GetBountyValue(self)); }
public void Infiltrated(Actor self, Actor infiltrator) { var targetResources = self.Owner.PlayerActor.Trait <PlayerResources>(); var spyResources = infiltrator.Owner.PlayerActor.Trait <PlayerResources>(); var toTake = (targetResources.Cash + targetResources.Resources) * info.Percentage / 100; var toGive = Math.Max(toTake, info.Minimum); targetResources.TakeCash(toTake); spyResources.GiveCash(toGive); Sound.PlayToPlayer(self.Owner, info.SoundToVictim); self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, infiltrator.Owner.Color.RGB, FloatingText.FormatCashTick(toGive), 30))); }
protected override void OnInside(Actor self) { if (target.IsDead) { return; } target.Owner.PlayerActor.Trait <PlayerResources>().GiveCash(payload); var exp = self.Owner.PlayerActor.TraitOrDefault <PlayerExperience>(); if (exp != null && target.Owner != self.Owner) { exp.GiveExperience(experience); } if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(target.CenterPosition, target.Owner.Color.RGB, FloatingText.FormatCashTick(payload), 30))); } }
protected override void OnEnterComplete(Actor self, Actor targetActor) { if (!string.IsNullOrEmpty(resourceType)) { var targetOwner = targetActor.Owner; var resources = targetOwner.PlayerActor.Trait <PlayerResources>(); var initialAmount = resources.Resources; if (!playerResources.Info.ResourceValues.TryGetValue(resourceType, out var resourceValue)) { return; } var value = resourceValue * payload; resources.GiveResources(value); var amount = resources.Resources - initialAmount; if (self.Owner.IsAlliedWith(self.World.RenderPlayer) && amount > 0) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(targetActor.CenterPosition, targetOwner.Color, FloatingText.FormatCashTick(amount), 30))); } foreach (var notify in targetActor.TraitsImplementing <INotifyResourceTransport>()) { notify.Delivered(spawner, targetActor); } } self.Dispose(); }
void ITick.Tick(Actor self) { Resources = playerResources.Resources; var CashGrant = Resources - ResourcesTickBefore; if (CashGrant > 0) { var temp = (int)Math.Ceiling((CashGrant * info.Percentage) / 100.0); playerResources.GiveResources(temp); if (info.ShowTicks && temp > 0) { if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(temp), 30))); } currentDisplayValue = 0; } } ResourcesTickBefore = playerResources.Resources; }
void GrantBounty() { if (currentBounty > 0) { var grantedBounty = currentBounty; if (Info.ShowBounty && self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(grantedBounty), 30))); } self.Owner.PlayerActor.Trait <PlayerResources>().GiveCash(currentBounty); currentBounty = 0; } }
void INotifyInfiltrated.Infiltrated(Actor self, Actor infiltrator, BitSet <TargetableType> types) { if (!info.Types.Overlaps(types)) { return; } var targetResources = self.Owner.PlayerActor.Trait <PlayerResources>(); var spyResources = infiltrator.Owner.PlayerActor.Trait <PlayerResources>(); var spyValue = infiltrator.Info.TraitInfoOrDefault <ValuedInfo>(); var toTake = Math.Min(info.Maximum, (targetResources.Cash + targetResources.Resources) * info.Percentage / 100); var toGive = Math.Max(toTake, info.Minimum >= 0 ? info.Minimum : spyValue != null ? spyValue.Cost : 0); targetResources.TakeCash(toTake); spyResources.GiveCash(toGive); if (info.InfiltratedNotification != null) { Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.InfiltratedNotification, self.Owner.Faction.InternalName); } if (info.InfiltrationNotification != null) { Game.Sound.PlayNotification(self.World.Map.Rules, infiltrator.Owner, "Speech", info.InfiltrationNotification, infiltrator.Owner.Faction.InternalName); } TextNotificationsManager.AddTransientLine(info.InfiltratedTextNotification, self.Owner); TextNotificationsManager.AddTransientLine(info.InfiltrationTextNotification, infiltrator.Owner); if (info.ShowTicks) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, infiltrator.Owner.Color, FloatingText.FormatCashTick(toGive), 30))); } }
public void Infiltrated(Actor self, Actor infiltrator) { var targetResources = self.Owner.PlayerActor.Trait <PlayerResources>(); var spyResources = infiltrator.Owner.PlayerActor.Trait <PlayerResources>(); var spyValue = infiltrator.Info.TraitInfoOrDefault <ValuedInfo>(); var toTake = (targetResources.Cash + targetResources.Resources) * info.Percentage / 100; var toGive = Math.Max(toTake, info.Minimum >= 0 ? info.Minimum : spyValue != null ? spyValue.Cost : 0); targetResources.TakeCash(toTake); spyResources.GiveCash(toGive); if (info.Notification != null) { Game.Sound.PlayNotification(self.World.Map.Rules, self.Owner, "Speech", info.Notification, self.Owner.Faction.InternalName); } self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, infiltrator.Owner.Color.RGB, FloatingText.FormatCashTick(toGive), 30))); }
void ITick.Tick(Actor self) { if (info.ShowTicks && currentDisplayValue > 0 && --currentDisplayTick <= 0) { var temp = currentDisplayValue; if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(temp), 30))); } currentDisplayTick = info.TickRate; currentDisplayValue = 0; } }
void INotifyCapture.OnCapture(Actor self, Actor captor, Player oldOwner, Player newOwner, BitSet <CaptureType> captureTypes) { if (IsTraitDisabled) { return; } if (!info.CaptureTypes.IsEmpty && !info.CaptureTypes.Overlaps(captureTypes)) { return; } var resources = newOwner.PlayerActor.Trait <PlayerResources>(); var amount = resources.ChangeCash(info.Amount); if (!info.ShowTicks && amount != 0) { return; } self.World.AddFrameEndTask(w => w.Add( new FloatingText(self.CenterPosition, self.Owner.Color, FloatingText.FormatCashTick(amount), info.DisplayDuration))); }
public override void Activate(Actor collector) { collector.World.AddFrameEndTask(w => { collector.Owner.PlayerActor.Trait <PlayerResources>().GiveCash(info.Amount); if (info.UseCashTick) { w.Add(new FloatingText(collector.CenterPosition, collector.Owner.Color.RGB, FloatingText.FormatCashTick(info.Amount), 30)); } }); base.Activate(collector); }
protected override void OnEnterComplete(Actor self, Actor targetActor) { var targetOwner = targetActor.Owner; var resources = targetOwner.PlayerActor.Trait <PlayerResources>(); var initialAmount = resources.Resources; var value = typeInfo.ValuePerUnit * payload; resources.GiveResources(value); var amount = resources.Resources - initialAmount; if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(targetActor.CenterPosition, targetOwner.Color, FloatingText.FormatCashTick(amount), 30))); } self.Dispose(); }
public override void DoImpact(Target target, Actor firedBy, IEnumerable <int> damageModifiers) { if (!firedBy.IsDead && firedBy.IsInWorld) { var playerResources = firedBy.Owner.PlayerActor.Trait <PlayerResources>(); playerResources.GiveResources(Ammount); if (ShowTicks && Ammount > 0 && firedBy.IsInWorld && !firedBy.IsDead) { if (firedBy.Owner.IsAlliedWith(firedBy.World.RenderPlayer)) { firedBy.World.AddFrameEndTask(w => w.Add(new FloatingText(firedBy.CenterPosition, firedBy.Owner.Color.RGB, FloatingText.FormatCashTick(Ammount), 30))); } } //Log.Write("debug", "GrantSelfConditionWarhead ::: DoImpact"); } }
public void Tick(Actor self) { // Harvester was killed while unloading if (dockedHarv != null && dockedHarv.IsDead()) { self.Trait <RenderBuilding>().CancelCustomAnim(self); dockedHarv = null; } if (Info.ShowTicks && currentDisplayValue > 0 && --currentDisplayTick <= 0) { var temp = currentDisplayValue; if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(temp), 30))); } currentDisplayTick = Info.TickRate; currentDisplayValue = 0; } }