コード例 #1
0
        public void Update(GameTime gameTime)
        {
            //First update client so it can read input and send appropriate events.
            if (client is LocalClient && client != null)
            {
                LocalClient lc = (LocalClient)client;
                lc.Update(gameTime);
            }

            if (server != null)
            {
                //Then update server so it can process events and send back the new level state.
                server.Update(gameTime);

                if (server is LocalServer)
                {
                    LocalServer ls = server as LocalServer;
                    // temp gameover check
                    Player player = ls.Level.Find(Player.LocalPlayerName) as Player;
                    if (player != null && player.Health <= 0)
                    {
                        GameOverState gos = GameEnvironment.GameStateManager.GetGameState("gameOverState") as GameOverState;
                        gos.GameMode = currentGameMode;
                        GameEnvironment.GameStateManager.SwitchTo("gameOverState");
                    }
                }
            }
        }
コード例 #2
0
        public RemoteClient(LocalServer server, TcpClient tcp) : base(server)
        {
            tcpClient       = tcp;
            binaryFormatter = new BinaryFormatter();

            StartReceiving();
        }
コード例 #3
0
        protected override void DoAction(LocalServer server, HashSet <GameObject> changedObjects)
        {
            Attacker.Attack(Defender);

            if (Defender.Health > 0)
            {
                changedObjects.Add(Defender);
            }
        }
コード例 #4
0
 public void openingChest()
 {
     if (Closed)
     {
         NonAnimationSoundEvent openedChestSoundEvent = new NonAnimationSoundEvent(openSound);
         LocalServer.SendToClients(openedChestSoundEvent);
         spriteAssetName = openContainerSprite;
     }
 }
コード例 #5
0
 protected override void DoAction(LocalServer server, HashSet <GameObject> changedObjects)
 {
     container.openingChest();
     changedObjects.Add(container);
     container.Closed = false;
     //TODO: sugetions:
     //1 init contents here to take specific players luck in to account.
     //2 if keys (for doors and chests) are implemented, add if(locked) with key requirement in validation
 }
コード例 #6
0
        public sealed override bool OnServerReceive(LocalServer server)
        {
            HashSet <GameObject> changed = new HashSet <GameObject>();

            DoAction(server, changed);
            player.ActionPoints -= Cost;

            changed.Add(player);
            LocalServer.SendToClients(new LevelChangedEvent(changed));
            return(true);
        }
コード例 #7
0
        protected override void DoAction(LocalServer server, HashSet <GameObject> changedObjects)
        {
            Tile oldTile = player.Tile;

            AddVisibleTiles(server.Level, changedObjects);
            player.MoveTo(tile);
            player.ComputeVisibility();
            AddVisibleTiles(server.Level, changedObjects);

            changedObjects.Add(oldTile.OnTile);
            changedObjects.Add(player.Tile.OnTile);
        }
コード例 #8
0
        public override bool OnServerReceive(LocalServer server)
        {
            player.AddStatPoint(stat);

            NonAnimationSoundEvent statSoundEvent = new NonAnimationSoundEvent("Sounds/CLICK10A", true, player.Id);

            LocalServer.SendToClients(statSoundEvent);

            LocalServer.SendToClients(new LevelChangedEvent(new List <GameObject> {
                player
            }));
            return(true);
        }
コード例 #9
0
        protected override void DoAction(LocalServer server, HashSet <GameObject> changedObjects)
        {
            door.Sprite.SheetIndex = (door.Sprite.SheetIndex + 1) % 2;
            door.Open();

            AddVisibleTiles(server.Level, changedObjects);
            player.ComputeVisibility();
            AddVisibleTiles(server.Level, changedObjects);

            changedObjects.Add(door);
            NonAnimationSoundEvent DoorSoundEvent = new NonAnimationSoundEvent("Sounds/door-1-open");

            LocalServer.SendToClients(DoorSoundEvent);
        }
コード例 #10
0
 public override void DoSkill(Living caster, Living livingTarget, Tile TileTarget)
 {
     if (livingTarget != null)
     {
         caster.Mana -= ManaCost;
         NonAnimationSoundEvent MagicBoldSound = new NonAnimationSoundEvent("Sounds/donnerre2");
         LocalServer.SendToClients(MagicBoldSound);
         livingTarget.TakeDamage(skillPower, DamageType.Magic);
     }
     else
     {
         throw new Exception("invalid target");
     }
 }
コード例 #11
0
        public override bool OnServerReceive(LocalServer server)
        {
            if (player.CurrentSkill != newSelectedSkill)
            {
                player.CurrentSkill = newSelectedSkill;
            }
            else
            {
                player.CurrentSkill = null;
            }

            NonAnimationSoundEvent selectSkillSound = new NonAnimationSoundEvent("Sounds/CLICK14A", true, player.Id);

            LocalServer.SendToClients(selectSkillSound);
            return(true);
        }
コード例 #12
0
        /// <summary>
        /// Adds exp to the players current exp. Can be a flat value or calculated based on the killed enemy his "power"
        /// </summary>
        /// <param name="expGained"></param>
        /// <param name="killedEnemy"></param>
        public void ReceiveExp(int expGained, Enemy killedEnemy = null)
        {
            if (killedEnemy != null)
            {
                int   expmod        = 50;
                float diffulcityMod = killedEnemy.statAverige / statAverige;
                expGained = (int)(diffulcityMod * expmod);
            }

            exp += expGained;

            while (exp >= RequiredExperience())
            {
                LevelUp();
                NonAnimationSoundEvent LevelUpSound = new NonAnimationSoundEvent("Sounds/Taiko_Drum_1", true, Id);
                LocalServer.SendToClients(LevelUpSound);
            }
        }
コード例 #13
0
        /// <summary>
        /// Puts the Living object on a given tile (if possible)
        /// </summary>
        /// <param name="t">Destination tile</param>
        public virtual void MoveTo(Tile t)
        {
            Tile oldTile = Tile;

            if (oldTile != null)
            {
                oldTile.RemoveImmediatly(this);
            }

            if (!t.PutOnTile(this))
            {
                if (!oldTile.PutOnTile(this))
                {
                    throw new Exception();
                }
            }
            else if (Visible)
            { //Movement animation
                LocalServer.SendToClients(new LivingMoveAnimationEvent(this, t, "Sounds/Footsteps 2 steps"));
            }
        }
コード例 #14
0
        private void AddStartGame()
        {
            Point      screen  = GameEnvironment.Screen;
            SpriteFont arial26 = GameEnvironment.AssetManager.GetFont("Arial26");

            startButton        = new Button("button", "Start Game", arial26, Color.Black);
            startButton.Action = () =>
            {
                foreach (Client c in clients)
                {
                    //send player type to the server - extra check to make sure correct type is known
                    ClientPlayerType CPT = new ClientPlayerType(c.ClientName, c.playerType);
                    Server.Send(CPT);
                }
                LocalServer ls = (LocalServer)server;
                ls.SetupLevel(1);

                GameEnvironment.GameStateManager.SwitchTo("playingState");
                GameEnvironment.AssetManager.StopMusic();
            };
            startButton.Position = new Vector2(screen.X - startButton.Width - 50, screen.Y - startButton.Height - 50);
            Add(startButton);
        }
コード例 #15
0
        public override bool OnServerReceive(LocalServer server)
        {
            List <GameObject> changed = new List <GameObject>();

            if (item != null)
            {
                changed.Add(item);
            }
            if (player.MouseSlot.Item != null)
            {
                changed.Add(player.MouseSlot.Item);
            }

            changed.Add(target);
            changed.Add(player.MouseSlot);
            changed.Add(player);//needed for skill slots
            player.MouseSlot.AddTo(item, target);

            NonAnimationSoundEvent pickupSound = new NonAnimationSoundEvent("Sounds/CLICK10B", true, player.Id);

            LocalServer.SendToClients(new LevelChangedEvent(changed));
            return(true);
        }
コード例 #16
0
        protected override void DoAction(LocalServer server, HashSet <GameObject> changedObjects)
        {
            potion.stackCount--;
            switch (potion.GetPotionType)
            {
            case PotionType.Health:
                player.Health += potion.PotionValue;
                NonAnimationSoundEvent PotionSoundEvent = new NonAnimationSoundEvent("Sounds/Potion Sound smaller");
                LocalServer.SendToClients(PotionSoundEvent);

                break;

            case PotionType.Mana:
                player.Mana += potion.PotionValue;
                NonAnimationSoundEvent PotionSoundEvent2 = new NonAnimationSoundEvent("Sounds/Potion Sound smaller");
                LocalServer.SendToClients(PotionSoundEvent2);
                break;

            default:
                throw new Exception("invalid potionType");
            }
            changedObjects.Add(potion);
        }
コード例 #17
0
        /// <summary>
        /// Handles attacking an opponent. First checks if attacker hits opponent, if succesfull sends attackvalue to defending side, if unsuccesfull displays miss feedback
        /// </summary>
        /// <param name="target"></param>
        public void Attack(Living target)
        {
            string     hitSound    = "Sounds/muted_metallic_crash_impact";
            int        damageDealt = 0;
            DamageType damageType  = DamageType.Physical;

            if (Weapon.SlotItem != null)
            {
                WeaponEquipment weaponItem = Weapon.SlotItem as WeaponEquipment;
                damageType = weaponItem.GetDamageType;
                hitSound   = weaponItem.HitSound;
            }

            //double hitNumber = GameEnvironment.Random.NextDouble();
            //if (hitNumber < HitChance())
            if (TryHit(target))
            {
                double attackValue = AttackValue();
                NonAnimationSoundEvent hitSoundEvent = new NonAnimationSoundEvent(hitSound);
                //no annimation for attacks (hit or miss) yet. when inplementing that, include sound effect there and remove this.
                LocalServer.SendToClients(hitSoundEvent);
                damageDealt = target.TakeDamage(attackValue, damageType);
            }
            else
            {
                //TODO: Display attack missed (visual feedback on fail)

                NonAnimationSoundEvent missSoundEvent = new NonAnimationSoundEvent("Sounds/Dodge");
                //no annimation for attacks (hit or miss) yet. when inplementing that, include sound effect there and remove this.
                LocalServer.SendToClients(missSoundEvent);
            }

            if (damageDealt > 0)
            {
                ProcessReflection(damageDealt, target);
            }
        }
コード例 #18
0
        public override bool OnServerReceive(LocalServer server)
        {
            NonAnimationSoundEvent nextLevelSound = new NonAnimationSoundEvent("Sounds/wooden-stairs-1");

            LocalServer.SendToClients(nextLevelSound);
            Level             level      = new Level(server.LevelIndex + 1);
            List <GameObject> playerlist = server.Level.FindAll(obj => obj is Player);

            for (int p = 1; p <= playerlist.Count; p++)
            {
                Player player = playerlist[p - 1] as Player;
                (level.Find("StartTile" + p) as Tile).PutOnTile(player);
                player.ActionPoints = Player.MaxActionPoints;
            }
            foreach (Player p in playerlist)
            {
                p.ComputeVisibility();
            }

            server.Level = level;

            LocalServer.SendToClients(new LevelUpdatedEvent(level));
            return(true);
        }
コード例 #19
0
 public override void OnServerReceive(LocalServer server)
 {
     throw new NotImplementedException();
 }
コード例 #20
0
 public override bool OnServerReceive(LocalServer server)
 {
     (Sender as RemoteClient).ClientName = clientName;
     return(true);
 }
コード例 #21
0
 public override bool OnServerReceive(LocalServer server)
 {
     server.Clients.Find(c => c.ClientName == ClientName).playerType = playerType;
     return(true);
 }
コード例 #22
0
 protected override void DoAction(LocalServer server, HashSet <GameObject> changedObjects)
 {
     changedObjects.Add(player);
     changedObjects.Add(trap);
     trap.disarmTrap(player);
 }
コード例 #23
0
 protected abstract void DoAction(LocalServer server, HashSet <GameObject> changedObjects);
コード例 #24
0
 protected override void DoAction(LocalServer server, HashSet <GameObject> changedObjects)
 {
     player.CurrentSkill.DoSkill(player, target as Living, target as Tile);
 }
コード例 #25
0
 public override bool OnServerReceive(LocalServer server)
 {
     server.EndTurn(player);
     return(true);
 }
コード例 #26
0
 public abstract bool OnServerReceive(LocalServer server);