예제 #1
0
        public void Update()
        {
            if (LastLevel < Level) {
                LevelUp();
                LastLevel = Level;
            }
            if (HP <= MaxHP / 3 && Game.Current.RNG.Next(5) == 0) BleedDirectly();
            if (TurnTimeout > 0) {
                TurnTimeout--;
                return;
            }
            if (AIType == AITypes.Zombie) {

                Point positionLast = new Point(Position.X, Position.Y);

                // Don't have a target? Let's find one!
                bool computedFOV = false;
                bool wandered = false;
                if (Target == null) {
                    if (!computedFOV) {
                        Area.Current.Map.computeFov(Position.X, Position.Y, ViewRadius, true, TCODFOVTypes.BasicFov);
                        computedFOV = true;
                    }
                    if (Area.Current.Map.isInFov(Game.Current.Player.Position.X, Game.Current.Player.Position.Y)) Target = Game.Current.Player;
                }

                // Is our target dead or something?
                if (Target != null && Target.HP < 1) Target = null;

                // OK, so we're chasing a target... can we still see him?
                if (Target != null) {
                    if (!computedFOV) {
                        Area.Current.Map.computeFov(Position.X, Position.Y, ViewRadius, true, TCODFOVTypes.BasicFov);
                        computedFOV = true;
                    }
                    if (Area.Current.Map.isInFov(Target.Position.X, Target.Position.Y)) {
                        foreach (Character c in Area.Current.Characters) {
                            if (c != this && c != Target) Area.Current.Map.setProperties(c.Position.X, c.Position.Y, true, false);
                        }
                        if (!Pathfinder.compute(Position.X, Position.Y, Target.Position.X, Target.Position.Y)) {
                            foreach (Character c in Area.Current.Characters) {
                                Area.Current.Map.setProperties(c.Position.X, c.Position.Y, true, true);
                            }
                            if (!Pathfinder.compute(Position.X, Position.Y, Target.Position.X, Target.Position.Y)) {
                                if (!wandered) {
                                    Wander();
                                    wandered = true;
                                }
                            }
                        }
                        else {
                            foreach (Character c in Area.Current.Characters) {
                                Area.Current.Map.setProperties(c.Position.X, c.Position.Y, true, true);
                            }
                        }
                    }
                }

                if (Pathfinder.size() > 1) {
                    int x, x2 = Position.X;
                    int y, y2 = Position.Y;
                    Pathfinder.get(0, out x, out y);
                    MoveToPosition(new Point(x, y));
                    if (Position.X == x && Position.Y == y) Pathfinder.walk(ref x2, ref y2, true);
                    else {
                        Target = null;
                        if (!wandered) {
                            Wander();
                            wandered = true;
                        }
                    }
                    TurnTimeout += 5 - Speed;
                }
                int dx, dy;
                Pathfinder.getDestination(out dx, out dy);
                if (Pathfinder.size() < 2 && Target != null && Target.Position.X == dx && Target.Position.Y == dy) {
                    MeleeAttack(Target);
                    idleTimer = 0;
                    TurnTimeout += 2;
                }

                if (Target == null && Pathfinder.size() < 2) {
                    if (!wandered) {
                        Wander();
                        wandered = true;
                    }
                }

                // Wander if you aren't attacking an enemy and have been standing still for too long
                if (positionLast == Position) idleTimer += 1;
                else idleTimer = 0;
                if (idleTimer > 3) {
                    idleTimer = 0;
                    if (!wandered) {
                        Wander();
                        wandered = true;
                    }
                }

            }
        }
예제 #2
0
 public void MeleeAttack(Character target)
 {
     int attackRoll = 1 + Game.Current.RNG.Next(20);
     int attackTotal = attackRoll + Character.StatToModifier(Strength);
     if (attackTotal > target.Defense) {
         int damage = 0;
         for (int i = 0; i < AttackMultiplier; i++) damage += (attackRoll == 20 ? damage = AttackDie + AttackDie / 2 : 1 + Game.Current.RNG.Next(AttackDie));
         target.Bleed();
         damage = Math.Max(damage + AttackModifier, 1);
         //if (attackRoll == 20) damage += damage / 2;
         Stamina = Math.Max(Stamina - 40, 0);
         target.HP -= damage;
         Console.WriteLine((attackRoll == 20 ? "Critical hit! " : "") + (this == Game.Current.Player ? "You do " : ToString() + " does ") + damage.ToString() + " damage to " + (target == Game.Current.Player ? "you" : target.ToString()) + (target.HP <= 0 ? ", killing " + (target == Game.Current.Player ? "you" : "it") + "." : "."));
         if (target.HP <= 0) {
             XP += target.HP / 2;
             target.Kill();
             Kills++;
         }
         XP += damage;
     }
     else {
         Console.WriteLine((this == Game.Current.Player ? "You swing" : ToString() + " swings") + " at " + (target == Game.Current.Player ? "you" : target.ToString()) + ", but " + (this == Game.Current.Player ? "miss." : "misses."));
     }
 }
예제 #3
0
 public static Character Generate(Prefab prefab, Point position)
 {
     Character c = new Character();
     switch (prefab) {
         case Prefab.Player:
             c.Name = "Adam";
             c.Symbol = '@';
             c.Infection = 0;
             c.Faction = Factions.Survivors;
             c.Strength = 16;
             c.Dexterity = 12;
             c.Constitution = 12;
             c.Intelligence = 12;
             c.AttackMultiplier = 1;
             c.AttackModifier = 4;
             c.Defense = 10;
             c.Speed = 2;
             c.MaxHP = 30;
             c.HP = c.MaxHP;
             c.ViewRadius = 23;
             break;
         case Prefab.Survivor:
             c.Symbol = '@';
             c.Infection = 0;
             c.Faction = Factions.Survivors;
             break;
         case Prefab.Zombie:
             c.Symbol = 'z';
             c.ForegroundColor = TCODColor.desaturatedGreen;
             c.Infection = 100;
             c.Faction = Factions.Undead;
             c.Strength = 8;
             c.Dexterity = 6;
             c.Constitution = 6;
             c.Intelligence = 4;
             c.AttackMultiplier = 1;
             c.AttackModifier = -2;
             c.Defense = 10;
             c.Speed = 1;
             c.MaxHP = 10;
             c.HP = c.MaxHP;
             c.AIType = AITypes.Zombie;
             c.ViewRadius = 14;
             break;
     }
     c.Area = Area.Current;
     c.Position = position;
     return c;
 }
예제 #4
0
 public Attitude AttitudeTowards(Character character)
 {
     switch (Faction) {
         case Factions.Survivors:
             switch (character.Faction) {
                 case Factions.Survivors: return Attitude.Friendly;
                 case Factions.Undead: return Attitude.Hostile;
                 case Factions.Military: return Attitude.Friendly;
             }
             break;
         case Factions.Undead:
             switch (character.Faction) {
                 case Factions.Survivors: return Attitude.Hostile;
                 case Factions.Undead: return Attitude.Friendly;
                 case Factions.Military: return Attitude.Hostile;
             }
             break;
         case Factions.Military:
             switch (character.Faction) {
                 case Factions.Survivors: return Attitude.Friendly;
                 case Factions.Undead: return Attitude.Hostile;
                 case Factions.Military: return Attitude.Friendly;
             }
             break;
     }
     return Attitude.Friendly;
 }
예제 #5
0
파일: Game.cs 프로젝트: adamrezich/zday
 public void Initialize()
 {
     Area.Current.Generate();
     Player = Character.Generate(Character.Prefab.Player, new Point(4, 4));
     Player.Weapon = new Weapon();
     Player.Weapon.AttackDie = 8;
     Player.Weapon.Class = "baseball bat";
 }