void switchPlayer() { var actor = ActorCache.Create(self.World, ActorType, self.Position, self.Team, isPlayer: true, health: RelativeHP); self.World.FinishPlayerSwitch(actor); self.Dispose(); }
void spawnMoney() { string[] types = { "gold", "silver", "silver", "silver" }; for (int i = 0; i < 800; i++) { var x1 = random.Next(4096 - 512) + 38 * 1024 - 256; var y1 = random.Next(1024 * 6) + 256; var init = new ParticleInit(ParticleCache.Types["beam"], new CPos(x1, y1, 0), random.Next(1024)); game.World.Add(new Particle(world, init)); game.World.Add(ActorCache.Create(game.World, types[random.Next(types.Length)], new CPos(x1, y1, 0))); } for (int i = 0; i < 800; i++) { var x2 = random.Next(4096 - 512) + 38 * 1024 - 256; var y2 = random.Next(1024 * 6) + 1024 * 9 - 256; var init = new ParticleInit(ParticleCache.Types["beam"], new CPos(x2, y2, 0), random.Next(1024)); game.World.Add(new Particle(world, init)); game.World.Add(ActorCache.Create(game.World, types[random.Next(types.Length)], new CPos(x2, y2, 0))); } }
public void Load() { Map.Load(); PathfinderLayer.Update(WallLayer, TerrainLayer); if (Game.InteractionMode != InteractionMode.EDITOR) { if (!Map.Type.IsSave) { LocalPlayer = ActorCache.Create(this, Game.Save.Actor, Map.PlayerSpawn, Actor.PlayerTeam, isPlayer: true); Add(LocalPlayer); } else { foreach (var team in Game.Save.Shroud.Keys) { ShroudLayer.RevealShroudList(team, Game.Save.Shroud[team]); } foreach (var condition in Game.Save.CustomConditions) { Game.ConditionManager.SetCondition(condition.Key, condition.Value); } LocalPlayer = ActorLayer.ToAdd().First(a => a.IsPlayer); } if (LocalPlayer.Health != null && Game.Save.Health > 0) { LocalPlayer.Health.RelativeHP = Game.Save.Health; } if (Game.IsCampaign && !Game.IsMenu) { AddText(LocalPlayer.Position, 300, ActionText.ActionTextType.TRANSFORM, $"Level {Game.Save.Level}"); } ShroudLayer.RevealAll = Program.DisableShroud; ShroudLayer.RevealAll |= Game.IsMenu || Game.MissionType == MissionType.TUTORIAL; } else { ShroudLayer.RevealAll = true; Camera.Position(Map.Center.ToCPos(), true); } // First tick, does only add objects, TODO replace with direct call to Tick() ActorLayer.Tick(); WeaponLayer.Tick(); ParticleLayer.Tick(); addObjects(); WorldRenderer.CheckVisibilityAll(); }
void spawnActor(string type, CPos position) { for (int i = 0; i < 20; i++) { var x = random.Next(1024) - 512 + position.X; var y = random.Next(1024) - 512 + position.Y; var init = new ParticleInit(ParticleCache.Types["beam"], new CPos(x, y, 0), random.Next(1024)); game.World.Add(new Particle(world, init)); } game.World.Add(ActorCache.Create(game.World, type, position)); }
public void PlayerKilled() { Game.Stats.Deaths++; Game.Save.IncreaseDeathCount(); if (Game.Stats.Lifes == 0) { Game.DefeatConditionsMet(); return; } Game.Stats.Lifes--; LocalPlayer = ActorCache.Create(this, Game.Save.Actor, Map.PlayerSpawn, Actor.PlayerTeam, isPlayer: true); Add(LocalPlayer); }
void createObject() { if (self.World.Game.SharedRandom.NextDouble() > info.Probability) { return; } var height = self.Height + info.Offset.Z; switch (info.Type) { case SpawnPartTypes.ACTOR: var actor = ActorCache.Create(self.World, info.Name, randomPosition(), info.InheritsTeam ? self.Team : Actor.NeutralTeam, info.InheritsBot && self.IsBot); if (info.InheritsBot && self.IsBot) { actor.Bot.Target = self.Bot.Target; } actor.Height = height; self.World.Add(actor); break; case SpawnPartTypes.PARTICLE: var particle = ParticleCache.Create(self.World, info.Name, randomPosition(), self.Height + info.Offset.Z); particle.Height = height; self.World.Add(particle); break; case SpawnPartTypes.WEAPON: var weapon = WeaponCache.Create(self.World, info.Name, randomPosition(), self); weapon.Height = height; self.World.Add(weapon); break; default: return; } }
public void BeginPlayerSwitch(ActorType to) { var health = LocalPlayer.Health != null ? LocalPlayer.Health.RelativeHP : 1; var playablePart = LocalPlayer.GetPartOrDefault <PlayablePart>(); if (playablePart != null && playablePart.PlayerSwitchActor == null) { FinishPlayerSwitch(ActorCache.Create(this, to, LocalPlayer.Position, LocalPlayer.Team, isPlayer: true, health: health)); LocalPlayer.Dispose(); return; } var switchActor = ActorCache.Create(this, playablePart.PlayerSwitchActor, LocalPlayer.Position, LocalPlayer.Team, isPlayer: true); var switchPart = switchActor.GetPart <PlayerSwitchPart>(); switchPart.RelativeHP = health; switchPart.ActorType = to; LocalPlayer.Dispose(); LocalPlayer.FollowupActor = switchActor; LocalPlayer = switchActor; Add(switchActor); }
void place() { if (currentSelected != Selected.WALL && !game.World.IsInWorld(MouseInput.GamePosition)) { return; } var pos = MouseInput.GamePosition; var mpos = pos.ToMPos(); var bounds = game.World.Map.Bounds; switch (currentSelected) { case Selected.ACTOR: if (actorWidget.CurrentType == null) { return; } if (actorWidget.RelativeHP == 0) { return; } pos = actorWidget.Rasterization ? rasterizedPosition(pos) : pos; var team = Math.Max(actorWidget.Team, (byte)0); var actor = ActorCache.Create(game.World, actorWidget.CurrentType, pos, team, actorWidget.Bot, false, actorWidget.RelativeHP); actor.Angle = actorWidget.RelativeFacing * Angle.MaxRange; game.World.Add(actor); break; case Selected.TILE: if (terrainWidget.CurrentType == null) { return; } if (mpos.X < 0 || mpos.Y < 0 || mpos.X >= bounds.X || mpos.Y >= bounds.Y) { return; } if (game.World.TerrainLayer.Terrain[mpos.X, mpos.Y].Type == terrainWidget.CurrentType) { return; } var terrain = TerrainCache.Create(game.World, mpos, terrainWidget.CurrentType.ID); game.World.TerrainLayer.Set(terrain); WorldRenderer.CheckTerrainAround(mpos, true); break; case Selected.WALL: if (wallWidget.CurrentType == null) { return; } if (mpos.X < 0 || mpos.Y < 0 || mpos.X > bounds.X || mpos.Y > bounds.Y) { return; } mpos = new MPos(mpos.X * 2 + (wallWidget.Horizontal ? 0 : 1), mpos.Y); var wallLayer = game.World.WallLayer; if (mpos.X >= wallLayer.Bounds.X - 2) { return; } if (mpos.Y >= wallLayer.Bounds.Y - 2 && wallWidget.Horizontal) { return; } var type = wallWidget.CurrentType; var plannedHealth = (int)(type.Health * wallWidget.RelativeHP); if (plannedHealth == 0 && type.Health != 0) { return; } var currentWall = wallLayer.Walls[mpos.X, mpos.Y]; if (currentWall != null && currentWall.Type.ID == type.ID && currentWall.Health == plannedHealth) { return; } var wall = WallCache.Create(mpos, wallLayer, type.ID); wall.Health = plannedHealth; wallLayer.Set(wall); break; } }
public void Impact(World world, Weapon weapon, Target target) { world.Add(ActorCache.Create(world, Type, target.Position, weapon.Team, IsBot)); }
public List <Actor> PlacePatrols() { var actors = new List <Actor>(); // TODO: rework in spawnbound areas positions.AddRange(world.Map.PatrolSpawnLocations); for (int a = 0; a < Math.Floor(bounds.X / (float)info.SpawnBounds); a++) { for (int b = 0; b < Math.Floor(bounds.X / (float)info.SpawnBounds); b++) { var pos = new MPos(a * info.SpawnBounds, b * info.SpawnBounds); if (!areaBlocked(a, b) && !positions.Contains(pos)) { positions.Add(pos); } } } var multiplier = bounds.X * bounds.Y / (float)(32 * 32) + (world.Game.Save.Difficulty - 5) / 10f; var count = random.Next((int)(info.MinimumPatrols * multiplier), (int)(info.MaximumPatrols * multiplier)); if (positions.Count < count) { Log.Warning($"Unable to spawn patrol count ({count}) because there are not enough available spawn points ({positions.Count})."); count = positions.Count; } spawns = new MPos[count]; for (int i = 0; i < count; i++) { var posIndex = random.Next(positions.Count); spawns[i] = positions[posIndex]; positions.RemoveAt(posIndex); } var map = world.Map; foreach (var spawn in spawns) { var mid = spawn.ToCPos(); var patrol = getPatrol(); var unitCount = patrol.ActorTypes.Length; var group = new List <Actor>(); for (int j = 0; j < unitCount; j++) { var spawnPosition = CPos.Zero; if (j == 0) { spawnPosition = mid; } else if (j < 7) { var angle = Angle.ToArc(60 * j); spawnPosition = mid + CPos.FromFlatAngle(angle, patrol.DistanceBetweenObjects); } else if (j < 19) { var angle = Angle.ToArc(30 * (j - 6)); spawnPosition = mid + CPos.FromFlatAngle(angle, 2 * patrol.DistanceBetweenObjects); } if (spawnPosition.X < map.TopLeftCorner.X + patrol.DistanceBetweenObjects / 2) { spawnPosition = new CPos(map.TopLeftCorner.X + patrol.DistanceBetweenObjects / 2, spawnPosition.Y, 0); } else if (spawnPosition.X >= map.BottomRightCorner.X - patrol.DistanceBetweenObjects / 2) { spawnPosition = new CPos(map.BottomRightCorner.X - patrol.DistanceBetweenObjects / 2, spawnPosition.Y, 0); } if (spawnPosition.Y < map.TopLeftCorner.Y + patrol.DistanceBetweenObjects / 2) { spawnPosition = new CPos(spawnPosition.X, map.TopLeftCorner.Y + patrol.DistanceBetweenObjects / 2, 0); } else if (spawnPosition.Y >= map.BottomRightCorner.Y - patrol.DistanceBetweenObjects / 2) { spawnPosition = new CPos(spawnPosition.X, map.BottomRightCorner.Y - patrol.DistanceBetweenObjects / 2, 0); } var actor = ActorCache.Create(world, patrol.ActorTypes[j], spawnPosition, patrol.Team, true); group.Add(actor); world.Add(actor); actors.Add(actor); } var groupPatrol = new Patrol(group); foreach (var actor in group) { if (actor.Bot != null) { actor.Bot.Patrol = groupPatrol; } } } return(actors); }