public void Leech(Actor self) { CPos cell = CPos.Zero; var cells = self.World.Map.FindTilesInCircle(self.World.Map.CellContaining(self.CenterPosition), 6, true) .Where(c => { if (!self.World.Map.Contains(c)) { return(false); } if (resLayer.GetResource(c) != null) { return(false); } return(true); }); if (cells != null && cells.Any()) { cell = self.ClosestCell(cells); } if (cell != CPos.Zero && resLayer.GetResourceDensity(cell) > 0) { var ammount = resLayer.GetResource(cell).Info.ValuePerUnit; if ((self.Owner.PlayerActor.Trait <PlayerResources>().Resources + ammount) <= self.Owner.PlayerActor.Trait <PlayerResources>().ResourceCapacity) { var playerResources = self.Owner.PlayerActor.Trait <PlayerResources>(); playerResources.GiveResources(ammount); if (ammount > 0 && self.IsInWorld && !self.IsDead) { if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, FloatingText.FormatCashTick(ammount), 30))); } } resLayer.Harvest(cell); } } }
void ITick.Tick(Actor self) { if (delay < 0) { return; } var adjacent = 0; foreach (var direction in CVec.Directions) { var location = self.Location + direction; var resource = resourceLayer.GetResourceType(location); if (resource == null || resource.Info.Type != info.Type) { continue; } var density = resourceLayer.GetResourceDensity(location); if (density < info.Density) { continue; } if (++adjacent < info.Adjacency) { continue; } delay--; break; } if (delay < 0) { Transform(self); } }
void ITick.Tick(Actor self) { if (IsTraitDisabled) { return; } if (tickler-- <= 0) { var cells = self.World.Map.FindTilesInCircle(self.Location, info.CollectRange, true) .Where(c => { if (resLayer.GetResource(c) == null) { return(false); } if (info.ResourcesNames.Contains(resLayer.GetResource(c).Info.Name)) { return(true); } return(false); }); var zapRandom = CPos.Zero; if (cells != null && cells.Any() && cells.Count() > 1) { zapRandom = cells.MinByOrDefault(c => (self.Location - c).LengthSquared); } else if (cells != null && cells.Any() && cells.Count() == 1) { zapRandom = cells.First(); } if (zapRandom != CPos.Zero) { var ammount = resLayer.GetResource(zapRandom).Info.ValuePerUnit; var playerResources = self.Owner.PlayerActor.Trait <PlayerResources>(); playerResources.GiveResources(ammount); if (ammount > 0 && self.IsInWorld && !self.IsDead) { var floattest = ammount.ToString(); floattest = "+ " + floattest + " Essence"; if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, floattest, 30))); } } resLayer.Harvest(zapRandom); if (resLayer.GetResourceDensity(zapRandom) <= 0) { resLayer.Destroy(zapRandom); } var weapon = Info.WeaponInfo; if (weapon == null) { return; } if (weapon.Report != null && weapon.Report.Any()) { Game.Sound.Play(SoundType.World, weapon.Report.Random(self.World.SharedRandom), self.CenterPosition); } weapon.Impact(Target.FromPos(self.World.Map.CenterOfCell(zapRandom)), self, Enumerable.Empty <int>()); tickler = info.CollectInterval; } } }
public int Leech(Actor self) { var validRes = new HashSet <string>(); foreach (var restype in resourceTypesPreres) { var hash = new List <string>(); hash.Add(restype.Value); if (restype.Value == "NONE") { validRes.Add(restype.Key); } else if (self.Owner.PlayerActor.TraitOrDefault <TechTree>().HasPrerequisites(hash)) { validRes.Add(restype.Key); } } CPos cell = CPos.Zero; var cells = self.World.Map.FindTilesInCircle(self.World.Map.CellContaining(self.CenterPosition), 6, true) .Where(c => { if (!self.World.Map.Contains(c)) { return(false); } if (resLayer.GetResource(c) == null) { return(false); } if (resLayer.GetResourceDensity(c) == 0) { return(false); } if (validRes.Contains(resLayer.GetResource(c).Info.Type)) { return(true); } return(false); }); if (cells != null && cells.Any()) { cell = self.ClosestCell(cells); } if (cell != CPos.Zero && resLayer.GetResourceDensity(cell) > 0) { var type = resLayer.GetResource(cell); var ammount = type.Info.ValuePerUnit + ReturnExtraTime(type); if ((self.Owner.PlayerActor.Trait <PlayerResources>().Resources + ammount) <= self.Owner.PlayerActor.Trait <PlayerResources>().ResourceCapacity) { var playerResources = self.Owner.PlayerActor.Trait <PlayerResources>(); playerResources.GiveResources(ammount); if (ammount > 0 && self.IsInWorld && !self.IsDead) { var floattest = ammount.ToString(); floattest = "+ " + floattest + " Essence"; if (self.Owner.IsAlliedWith(self.World.RenderPlayer)) { self.World.AddFrameEndTask(w => w.Add(new FloatingText(self.CenterPosition, self.Owner.Color.RGB, floattest, 30))); } } resLayer.Harvest(cell); if (resLayer.GetResourceDensity(cell) <= 0) { resLayer.Destroy(cell); } return(ammount); } } return(0); }