public MonsterDef GetMonsterForLevel() { // returns the monster def for this level if (needsRebuildPercent) { RebuildPercent(); } float rand = Random.value * totalWeight; MonsterDef selectedMonster = null; foreach (PossibleMonster p in possibleMonsters) { if (rand < p.percent) { // found our monster // find it in the monster defs Debug.Log("found monster! " + p.name); foreach (MonsterDef m in MonsterDef.monsterDefs) { if (m.name == p.name) { selectedMonster = m; } } break; } rand -= p.percent; } if (selectedMonster == null) { Debug.LogError("couldn't find requested monster: " + rand); } return(selectedMonster); }
public IMonster AddMonster(MonsterDef monsterDef) { var monsterFactory = new MonsterFactory(); var result = monsterFactory.BuildMonster(monsterDef); this._gameObjectCollection.Add(result); return(result); }
public DungeonMonster(MonsterDef def, Vector2?position) : base(def, position, "Up", 0, "monsters") { MonsterDef = def; MiniMapTile = MiniMapTile.Monster; DrawIndex = (int)def.Monster; NextMove = ""; Origin = new(8, 8); }
public MonsterEgg(MonsterDef underlyingMonster, int timeToHatch) : base(underlyingMonster.Position) { this._underlyingMonster = underlyingMonster; this.Energy = underlyingMonster.Energy; this._animationPlayer = new LoopedAnimation(this, "Sprites/Monsters/Egg", 6); var timeSpan = TimeSpan.FromSeconds(timeToHatch * Constants.GameClockResolution); this._hatchingTimer = GameTimer.AddGameTimer(timeSpan, EggIsHatching, false); this.Properties.Set(GameObjectProperties.DrawOrder, (int)SpriteDrawOrder.StaticMonster); this.Properties.Set(GameObjectProperties.Solidity, ObjectSolidity.Stationary); }
private static Monster BuildMonsterFromBreed([NotNull] Breed breedInfo, MonsterDef monsterDef) { var pathToTexture = "Sprites/Monsters/" + breedInfo.Texture; if (breedInfo.Name == "Tank") { return(new Tank(monsterDef)); } var result = new Monster(monsterDef, pathToTexture, breedInfo.BaseMovesDuringAnimation); return(result); }
private static IMonster BuildEgg(MonsterDef monsterDef) { if (!monsterDef.TimeBeforeHatching.HasValue) { throw new InvalidOperationException("MonsterDef has IsEgg set without a TimeBeforeHatching value."); } var underlyingMonster = monsterDef; underlyingMonster.IsEgg = false; underlyingMonster.TimeBeforeHatching = null; var result = new MonsterEgg(underlyingMonster, monsterDef.TimeBeforeHatching.Value); return(result); }
public DummyMonster(MonsterDef monsterDef, string textureName, int baseMovesDuringAnimation) : base(monsterDef, textureName, baseMovesDuringAnimation) { this.Mobility = MonsterMobility.Placid; this.Activate(); var action = new DummyAction(); action.Init(this); this.Behaviours.Add(action); var action2 = new Flitter(); action2.Init(this); this.Behaviours.Add(action2); }
private void Update(object sender, System.EventArgs e) { frameLabel.Text = "Frame: " + InputManager.CurrentFrame; var c = CharMgr.GetPlayerCharacter(PlayerMgr.GetMainPlayer()); xLabel.Text = "Pos X: " + c?.loc.X; yLabel.Text = "Pos Y: " + c?.loc.Y; xSpeedLabel.Text = "Spd X: " + c?.traj.X; ySpeedLabel.Text = "Spd Y: " + c?.traj.Y; MouseState mouse = InputManager.GetActualMouse(); mouseXLabel.Text = "Pos X: " + mouse.X; mouseYLabel.Text = "Pos Y: " + mouse.Y; var charAnim = c?.anim; animNameLabel.Text = "Name: " + charAnim?.animName; animKeyLabel.Text = "Key: " + charAnim?.key; animFrameLabel.Text = "Frame: " + charAnim?.frame; KeyFrame frame; try { MonsterDef mDef = MonsterCatalog.catalog[c.monsterIdx]; CharDef charDef = CharDefMgr.charDefList[mDef.defIdx]; Animation anim = charDef.animation[charAnim.anim]; frame = anim.keyFrame[charAnim.key]; } catch { frame = null; } animFrameDurationLabel.Text = "Duration: " + frame?.duration; if (NeedsClose) { NeedsClose = false; Close(); } else { Invalidate(); } }
public IMonster AddDiamondDemon(Vector2 p) { MonsterDef md = new MonsterDef { Breed = "DiamondDemon", Position = p, Energy = 30, Mobility = MonsterMobility.Aggressive, LaysEggs = true, ChangeRooms = ChangeRooms.FollowsPlayer, ShootsAtPlayer = Setting <ShootsAtPlayer> .NewSetting(ShootsAtPlayer.Immediately) }; var result = AddMonster(md); return(result); }
public void AddGameObjects(GameState gameState) { var lines = this._layout.Split(new [] { "\r\n" }, StringSplitOptions.None); for (int y = 0; y < lines.Count(); y++) { for (int x = 0; x < lines[y].Length; x++) { var tp = new TilePos(x, y); var position = tp.ToPosition(); var c = lines[y][x]; switch (c) { case ' ': break; case '#': Trace.WriteLine(System.IO.Directory.GetCurrentDirectory()); gameState.AddWall(position, "Tiles/Floor1"); break; case 'p': gameState.AddPlayer(position, 255, 0); break; case 'b': gameState.AddBoulder(position); break; case 'g': gameState.AddGrave(tp); break; case 'm': var mdef = new MonsterDef(); mdef.Breed = "DummyMonster"; mdef.Position = position; mdef.Energy = 100; gameState.AddMonster(mdef); break; default: throw new InvalidOperationException(); } } } }
public override void Perform() { if (!ShouldAttemptToLayEgg()) { return; } TilePos tp = this.Monster.TilePosition; if (!GlobalServices.GameState.IsStaticItemOnTile(tp)) { this.PlaySound(GameSound.MonsterLaysEgg); MonsterDef md = this.Monster.Definition; md.Position = this.Monster.TilePosition.ToPosition(); md.InitialDirection = Direction.None; md.IsEgg = true; md.TimeBeforeHatching = (this.Random.Next(256) & 0x1f) + 8; md.LaysEggs = false; // original game says hatched monsters do not lay eggs themselves GlobalServices.GameState.AddMonster(md); } }
public Monster(MonsterDef definition, string textureName, int baseMovesDuringAnimation) : this(definition) { this.AnimationPlayer = new LoopedAnimation(this, textureName, baseMovesDuringAnimation); }
public Marshall(MonsterDef def, Vector2?position) : base(def, position) { }
public IMonster BuildMonster(MonsterDef monsterDef) { if (monsterDef.IsEgg) { return(BuildEgg(monsterDef)); } var breedInfo = Breeds[monsterDef.Breed]; var result = BuildMonsterFromBreed(breedInfo, monsterDef); AddInherentBehaviours(result, breedInfo); AddMovements(result, breedInfo); AddInherentProperties(result, breedInfo); if (monsterDef.Mobility.HasValue) { result.Mobility = monsterDef.Mobility.Value; } if (monsterDef.ChangeRooms.HasValue) { result.ChangeRooms = monsterDef.ChangeRooms.Value; } if (!monsterDef.MobilityAfterInjury.UseBreedDefault) { result.Behaviours.Remove <MobilityAfterInjury>(); if (monsterDef.MobilityAfterInjury.UseSpecificBehaviour) { result.Behaviours.Add(new MobilityAfterInjury(result, monsterDef.MobilityAfterInjury.SpecificBehaviour)); } } if (!monsterDef.ChangeRoomsAfterInjury.UseBreedDefault) { result.Behaviours.Remove <ChangeRoomsAfterInjury>(); if (monsterDef.ChangeRoomsAfterInjury.UseSpecificBehaviour) { result.Behaviours.Add(new ChangeRoomsAfterInjury(result, monsterDef.ChangeRoomsAfterInjury.SpecificBehaviour)); } } if (monsterDef.LaysMushrooms.HasValue) { result.Behaviours.Set <LaysMushroom>(monsterDef.LaysMushrooms.Value); } if (monsterDef.LaysEggs.HasValue) { result.Behaviours.Set <LaysEgg>(monsterDef.LaysEggs.Value); } if (monsterDef.SplitsOnHit.HasValue) { result.Behaviours.Set <SpawnsUponDeath>(monsterDef.SplitsOnHit.Value); } if (!monsterDef.ShootsAtPlayer.UseBreedDefault) { result.Behaviours.Remove <Behaviour.ShootsAtPlayer>(); result.Behaviours.Remove <StartsShootingWhenHurt>(); switch (monsterDef.ShootsAtPlayer.SpecificBehaviour) { case ShootsAtPlayer.Immediately: result.Behaviours.Add <Behaviour.ShootsAtPlayer>(); break; case ShootsAtPlayer.OnceInjured: result.Behaviours.Add <StartsShootingWhenHurt>(); break; default: throw new InvalidOperationException("Unknown setting for ShootsAtPlayer"); } } if (monsterDef.ShotsBounceOff.HasValue) { if (monsterDef.ShotsBounceOff.Value) { result.Properties.Set(GameObjectProperties.EffectOfShot, EffectOfShot.Reflection); } else { result.Properties.Remove(GameObjectProperties.EffectOfShot); } } if (monsterDef.IsActive.GetValueOrDefault()) { result.Activate(); } if (!result.IsActive) { result.Behaviours.Add <ActivateWhenHurt>(); result.Behaviours.Add <ActivateWhenMeetsPlayer>(); } if (result.Mobility != MonsterMobility.Stationary && result.MovementBoundary == null) { throw new InvalidOperationException("Monster of type " + monsterDef.Breed + " at " + monsterDef.Position + " has no movement boundary. Presumably ChangeRooms has not been set."); } result.SetMonsterMotion(true); result.Properties.Set(GameObjectProperties.MovementChecker, MovementCheckerForMonsters); return(result); }
protected Monster(MonsterDef definition) : base(definition.Position) { this.Definition = definition; this.Energy = definition.Energy; this.Behaviours = new BehaviourCollection(this); }
public Tank(MonsterDef definition) : base(definition) { this.AnimationPlayer = new TankAnimation(this); this._turret = new Turret(this); }
public Snake(MonsterDef def, Vector2?position) : base(def, position) { }