コード例 #1
0
        /// <summary>
        /// Process when a player changes fightMode or fightStance.
        /// </summary>
        /// <param name="player">The player changing the mode.</param>
        /// <param name="world">A reference to the gameworld.</param>
        private void ProcessChangeMode(Player player, GameWorld world)
        {
            byte rawFightMode = netmsg.GetByte(); //Agressive, normal, defensive
            byte rawFightStance = netmsg.GetByte(); //Follow, run away, stand still
            bool isFightModeValid = Enum.IsDefined(typeof(FightMode), rawFightMode);
            bool isFightStanceValid = Enum.IsDefined(typeof(FightStance), rawFightStance);

            //Make sure modes are valid
            if (!isFightModeValid || !isFightStanceValid)
            {
                return;
            }

            FightMode fightMode = (FightMode)rawFightMode;
            FightStance fightStance = (FightStance)rawFightStance;
            #if DEBUG
            Log.WriteDebug("In ProcessChangeMode()");
            Log.WriteDebug("fightMode: " + fightMode);
            Log.WriteDebug("fightStance: " + fightStance);
            #endif
            world.HandleChangeMode(player, fightMode, fightStance);
        }
コード例 #2
0
ファイル: Server.cs プロジェクト: brewsterl/berserker
        public void Run(string[] args)
        {
            // TODO: Print version information
            #if DEBUG
            // TODO: Print "DEBUGGING ON"-message
            Log.WriteDebug("Debugging on.");
            #endif
            // Load configuration
            // Remove configuration asm/
            if (Directory.Exists("asm"))
                Directory.Delete("asm", true);

            string configFile = "config.cs";

            // Read config file in command line argument
            if (args.Length > 0)
            {
                if (!File.Exists(args[0]))
                {
                    Console.WriteLine("Usage: mono Berserker.exe [config file]");
                    Console.WriteLine();

                    return;
                }
                else
                {
                    configFile = args[0];
                }
            }

            if (!File.Exists(configFile))
            {
                // TODO: Create new template config file
                configFile = "config.cs";
            }

            Log.WriteBegin("Loading config file (" + configFile + ")...");

            try
            {
                Compiler compiler = new Compiler();
                Dictionary<string, string> values = (Dictionary<string, string>) compiler.Compile(configFile, null);

                Config.Load(values);
            }
            catch (Exception e)
            {
                Log.WriteError(e.ToString());

                return;
            }

            Log.WriteEnd();

            // TODO: Write load-message
            Log.WriteBegin("Loading items...");
            Item.LoadItems();
            Log.WriteEnd();

            // TODO: Write load-message
            Log.WriteBegin("Loading spells...");
            Spell.Load();
            Log.WriteEnd();

            // TODO: Write load-message
            Log.WriteBegin("Loading monsters...");
            Monster.Load();
            Log.WriteEnd();

            // TODO: Write load-message
            Log.WriteBegin("Loading commands...");
            Command.Load();
            Log.WriteEnd();

            // TODO: Write load-message
            Log.WriteBegin("Loading map...");
            Map map = Map.Load();
            world = new GameWorld(map);
            Log.WriteEnd();

            // TODO: Write load-message
            Log.WriteBegin("Loading non-person characters...");
            NPC.Load();
            List<NPC> allNPCs = NPC.GetAllNPCs();

            foreach (NPC npc in allNPCs)
                world.SendAddNPC(npc, npc.CurrentPosition);

            Log.WriteEnd();

            // TODO: Write load-message
            Log.WriteBegin("Loading monster spawns...");
            Respawn.Load(world);
            Log.WriteEnd();

            // TODO: Write load-message (listener)
            Log.WriteBegin("Starting TCP listener...");
            listener = new TcpListener(IPAddress.Any, Config.GetPort());
            listener.Start();
            Log.WriteEnd();

            Log.WriteLine("Server is now running.");
            // TODO: Write message: SERVER NOW RUNNING

            AcceptConnections();
        }
コード例 #3
0
ファイル: Respawn.cs プロジェクト: brewsterl/berserker
 public Respawn(GameWorld gameWorld)
 {
     world = gameWorld;
 }
コード例 #4
0
ファイル: Item.cs プロジェクト: brewsterl/berserker
 /// Returns whether to let the gameworld proceed with the walk.
 /// True if the gameworld should proceed, false if this thing handles
 /// it fully.
 /// </summary>
 /// <param name="player">The player walking.</param>
 /// <param name="world">A reference to the game world.</param>
 /// <returns></returns>
 public override void UseThing(Player user, GameWorld world)
 {
     if (useItems.ContainsKey(this.ItemID)) {
         useItems[ItemID].Invoke(this, user, world);
     }
 }
コード例 #5
0
ファイル: Container.cs プロジェクト: brewsterl/berserker
 /// <summary>
 /// Use the thing.
 /// </summary>
 /// <param name="user">The player using the thing.</param>
 public override void UseThing(Player user, GameWorld world)
 {
     user.OpenContainer(this);
 }
コード例 #6
0
ファイル: CheckSystem.cs プロジェクト: brewsterl/berserker
 public void DoAction(GameWorld world)
 {
     world.HandlePush(player, posFrom, thingID, stackpos, posTo, count);
     player.CurrentDelayedAction = null;
 }
コード例 #7
0
ファイル: Item.cs プロジェクト: brewsterl/berserker
 public override void AppendHandlePush(Player player, Position posFrom, ushort thingID,
     byte stackpos, Position posTo, byte count, GameWorld world)
 {
     world.GetMovingSystem().HandlePush(player, posFrom, thingID, stackpos, posTo, count, this);
 }
コード例 #8
0
 /// <summary>
 /// Process a player's house text submission.
 /// </summary>
 /// <param name="player">The player doing the action.</param>
 /// <param name="world">A reference to the gameworld.</param>
 private void ProcessHouseText(Player player, GameWorld world)
 {
     // TODO: Not implemented?
     byte type = netmsg.GetByte();
     uint windowID = netmsg.GetU32();
     string txt = netmsg.GetStringL();
 }
コード例 #9
0
 /// <summary>
 /// Process a player's logout.
 /// </summary>
 /// <param name="player">The player doing the action.</param>
 /// <param name="world">A reference to the gameworld.</param>
 private void ProcessLogout(Player player, GameWorld world)
 {
     #if DEBUG
     Log.WriteDebug("In ProcessLogout()");
     #endif
     world.HandleLogout(player);
 }
コード例 #10
0
        /// <summary>
        /// Process when a player sends a comment.
        /// </summary>
        /// <param name="player">The player doing the action.</param>
        /// <param name="world">A reference to the gameworld.</param>
        private void ProcessComment(Player player, GameWorld world)
        {
            string comment = netmsg.GetStringZ();
            FileHandler fileHandler = new FileHandler();

            lock (lockStatic)
            {
                fileHandler.SaveComment(comment, player);
            }

            player.ResetNetMessages();
            player.AddAnonymousChat(ChatAnonymous.WHITE, "Your comment has been submitted");
            player.WriteToSocket();
        }
コード例 #11
0
 /// <summary>
 /// Process when a player leaves his battle screen.
 /// </summary>
 /// <param name="player">The player who exits his battle screen.</param>
 /// <param name="world">A reference to the gameworld.</param>
 private void ProcessExitBattle(Player player, GameWorld world)
 {
     #if DEBUG
     Log.WriteDebug("In ProcessExitBattle()");
     #endif
     world.HandleExitBattle(player);
 }
コード例 #12
0
        /// <summary>
        /// Process when a player closes a container.
        /// </summary>
        /// <param name="player">The player who closes the container.</param>
        /// <param name="world">A reference to the gameworld.</param>
        private void ProcessCloseContainer(Player player, GameWorld world)
        {
            byte localID = netmsg.GetByte();

            if (localID > Constants.MAX_CONTAINERS)
            {
                return;
            }

            world.HandleCloseContainer(player, localID);
        }
コード例 #13
0
        /// <summary>
        /// Process when a player says something.
        /// </summary>
        /// <param name="player">The player who is talking.</param>
        /// <param name="world">A reference to the gameworld.</param>
        private void ProcessChat(Player player, GameWorld world)
        {
            string msg; // Thing that the player is saying
            msg = netmsg.GetStringL();

            //Test for acceptable string length
            if (msg.Length > MAX_STRING_LENGTH)
            {
                return;
            }
            #if DEBUG
            Log.WriteDebug("In ProcessChat()");
            Log.WriteDebug("msg: " + msg);
            #endif
            world.HandleChat(player, msg);
        }
コード例 #14
0
        /// <summary>
        /// Process a player's change outfit.
        /// </summary>
        /// <param name="player">The player doing the action.</param>
        /// <param name="world">A reference to the gameworld.</param>
        private void ProcessChangeOutfit(Player player, GameWorld world)
        {
            uint newOutfit;

            newOutfit = netmsg.GetU32();
            //world.SendPlayerChangeOutfit(p, newOutfit);
        }
コード例 #15
0
        /// <summary>
        /// Process when a player uses an item.
        /// </summary>
        /// <param name="player">The player who uses the item.</param>
        /// <param name="world">A reference to the gameworld.</param>
        private void ProcessUseItem(Player player, GameWorld world)
        {
            byte itemType = netmsg.GetByte(); //1 = regular, 2 = usable with
            Position pos = netmsg.GetPosition();
            ushort itemID = netmsg.GetU16();
            byte stackpos = netmsg.GetByte();

            byte unknownByte = netmsg.GetByte(); //unknown?? TODO: Figure out
            #if DEBUG
            Log.WriteDebug("In ProcessUseItem()");
            Log.WriteDebug("itemType: " + itemType);
            Log.WriteDebug("pos: " + pos);
            Log.WriteDebug("itemID: " + itemID);
            Log.WriteDebug("stackpos: " + stackpos);
            Log.WriteDebug("unknownbyte: " + unknownByte);
            #endif
            if (itemType == Constants.ITEM_TYPE_USE)
            {
                world.HandleUseItem(player, itemType, pos, itemID, stackpos);
            }
            else if (itemType == Constants.ITEM_TYPE_USE_WITH)
            {
                Position posWith = netmsg.GetPosition();
                ushort spriteIDWith = netmsg.GetU16();
                byte stackposWith = netmsg.GetByte();
            #if DEBUG
                Log.WriteDebug("posWith: " + posWith);
                Log.WriteDebug("spriteid with: " + spriteIDWith);
                Log.WriteDebug("stackPos: " + stackposWith);
            #endif
                world.HandleUseItemWith(player, itemType, pos, itemID, stackpos, posWith, stackposWith);
            }

            /*if (Item.CreateItem(itemID).IsOfType(Constants.TYPE_USEABLE_WITH)){
                Position posWith = netmsg.GetPosition();
                world.SendPlayerUseItem(p, pos, itemID, stackpos, posWith);
            } else {
                world.SendPlayerUseItem(p, pos, itemID, stackpos, null);
            }*/
        }
コード例 #16
0
 /// <summary>
 /// Process when a player looks at something.
 /// </summary>
 /// <param name="player">The player who is looking.</param>
 /// <param name="world">A reference to the gameworld.</param>
 private void ProcessLookAt(Player player, GameWorld world)
 {
     //Position player is looking at
     Position pos = netmsg.GetPosition();
     #if DEBUG
     Log.WriteDebug("In ProcessLookAt()");
     Log.WriteDebug("pos: " + pos);
     #endif
     world.HandleLookAt(player, pos);
 }
コード例 #17
0
        /// <summary>
        /// Process a player's walk.
        /// </summary>
        /// <param name="player">The player doing the action.</param>
        /// <param name="world">A reference to the gameworld.</param>
        private void ProcessWalk(Player player, GameWorld world)
        {
            byte rawDirection = netmsg.GetByte();

            //Validate direction
            if (!IsDirectionValid(rawDirection))
                return;

            Direction direction; //direction to move

            direction = (Direction)rawDirection;
            #if DEBUG
            Log.WriteDebug("In ProcessWalk()");
            Log.WriteDebug("direction: " + direction);
            #endif
            world.HandleManualWalk(player, direction);

            /* p.SetTargetPosition(null);

             if (p.GetLastWalk().Elapsed()) //Enough time passed
                 world.SendCreatureWalk(p, direction);*/
        }
コード例 #18
0
        /// <summary>
        /// Attemps to read from the socket or blocks until
        /// a message is ready to be read and if successful, it 
        /// processes that message.
        /// </summary>
        /// <param name="player">Player doing the action.</param>
        /// <param name="world">A reference to the game world.</param>
        /// <returns>Returns true if to continue processing messages, 
        /// false otherwise.</returns>
        private bool ProcessNextMessage(Player player, GameWorld world)
        {
            // TODO: Handle logging out disposed error... ;/
            if (!netmsg.Connected())
            {
                return false;
            }

            netmsg.Reset();
            ushort header = netmsg.GetU16();

            if (header > HEADER_MAX_VAL)
            {
                throw new Exception("Invalid header sent. Header: " + header);
            }

            // Only process loged in player's messages, unless player
            // wants to log out
            if (!world.IsCreatureLogedIn(player))
            {
                // TODO: Check for CTRL+L logout? Different header?
                // Logout header
                if (header == 0xFF)
                {
                    player.Logout();

                    return false;
                }
            }
            else if (messageDecoder[header] == null)
            {
                PrintHeader(netmsg, header);
            }
            else
            {
                messageDecoder[header].Invoke(player, world);
            }

            return true;
        }
コード例 #19
0
ファイル: CheckSystem.cs プロジェクト: brewsterl/berserker
 public void DoAction(GameWorld world)
 {
     world.HandleUseItem(player, itemType, pos, itemID, stackpos);
     player.CurrentDelayedAction = null;
 }
コード例 #20
0
        /// <summary>
        /// Process a player's push.
        /// </summary>
        /// <param name="player">The player doing the action.</param>
        /// <param name="world">A reference to the gameworld.</param>
        private void ProcessPush(Player player, GameWorld world)
        {
            Position posFrom = netmsg.GetPosition();
            ushort thingID = netmsg.GetU16();
            byte stackpos = netmsg.GetByte();
            Position posTo = netmsg.GetPosition();
            byte count = netmsg.GetByte();
            #if DEBUG
            Log.WriteDebug("In ProcessPush()");
            Log.WriteDebug("posFrom: " + posFrom);
            Log.WriteDebug("thingID: " + thingID);
            Log.WriteDebug("stackpos: " + stackpos);
            Log.WriteDebug("posTo: " + posTo);
            Log.WriteDebug("count: " + count);
            #endif
            if (count == 0)
            {
                return;
            }

            world.HandlePush(player, posFrom, thingID, stackpos, posTo, count);
        }
コード例 #21
0
ファイル: Item.cs プロジェクト: brewsterl/berserker
 public override bool HandleWalkAction(Creature creature, GameWorld world, WalkType type)
 {
     if (walkItems.ContainsKey(this.ItemID)) {
         return walkItems[ItemID](this, creature, world, type);
     }
     return true;
 }
コード例 #22
0
 /// <summary>
 /// Process a player's request on changing outfit.
 /// </summary>
 /// <param name="player">The player doing the action.</param>
 /// <param name="world">A reference to the gameworld.</param>
 private void ProcessRequestOutfit(Player player, GameWorld world)
 {
     world.HandleRequestOutfit(player);
 }
コード例 #23
0
ファイル: Item.cs プロジェクト: brewsterl/berserker
        public override void UseThingWith(Player user, Position posWith, GameWorld world,
            byte stackposWith)
        {
            string attr = GetAttribute(Constants.ATTRIBUTE_RUNES_SPELL_NAME);
            if (attr != null) {
                Spell spell = Spell.CreateRuneSpell(attr, user, posWith);
                spell.Rune = this;
                spell.UseWithPos = posWith;
                spell.UseWithStackpos = stackposWith;
                world.GetSpellSystem().CastSpell(spell.Name, user, spell, world);
                return;
            }

            if (useItemsWith.ContainsKey(ItemID)) {
                useItemsWith[ItemID](this, user, world, posWith, stackposWith);
            }
        }
コード例 #24
0
 /// <summary>
 /// Process setting an outfit.
 /// </summary>
 /// <param name="player">The player doing the action.</param>
 /// <param name="world">A reference to the gameworld.</param>
 private void ProcessSetOutfit(Player player, GameWorld world)
 {
     byte upper = netmsg.GetByte();
     byte middle = netmsg.GetByte();
     byte lower = netmsg.GetByte();
     #if DEBUG
     Log.WriteDebug("In ProcessSetOutfit()");
     Log.WriteDebug("Upper: " + upper);
     Log.WriteDebug("Middle: " + middle);
     Log.WriteDebug("Lower: " + lower);
     #endif
     world.HandleSetOutfit(player, lower, middle, upper);
 }
コード例 #25
0
ファイル: MovingSystem.cs プロジェクト: brewsterl/berserker
 /// <summary>
 /// Construct this object.
 /// </summary>
 /// <param name="gameMap">Reference to the game map.</param>
 public MovingSystem(Map gameMap, GameWorld gameWorld)
 {
     map = gameMap;
     world = gameWorld;
 }
コード例 #26
0
 /// <summary>
 /// Process when a player attacks a target.
 /// </summary>
 /// <param name="player">The attacker.</param>
 /// <param name="world">A reference to the gameworld.</param>
 private void ProcessSetTarget(Player player, GameWorld world)
 {
     uint targetID = netmsg.GetU32();
     world.HandleCreatureTarget(player, targetID);
 }
コード例 #27
0
ファイル: SpellSystem.cs プロジェクト: brewsterl/berserker
        /// <summary>
        /// Use this method cast the specified spell. Note: This method only
        /// appends and does not send protocol data.
        /// </summary>
        /// <param name="caster">The creature casting the spell</param>
        /// <param name="spell">The spell to cast</param>
        /// <param name="tSet">The set of affected things</param>
        public void CastSpell(string msg, Creature caster, Spell spell, GameWorld world)
        {
            /*string error = caster.CanCastSpell(spell);
            if (error != null) {
                caster.AddAnonymousChat(ChatAnonymous.WHITE, error);
                return;
            }*/ //TODO: Uncomment

            if (spell.IsSpellValid != null && !spell.IsSpellValid(world, msg)) {
                world.AddMagicEffect(MagicEffect.PUFF, caster.CurrentPosition);
                return;
            }
            if (spell.RequiresTarget) {
                Tile tile = map.GetTile(spell.SpellCenter);
                if (tile == null || !tile.ContainsType(Constants.TYPE_CREATURE)) {
                    world.AddMagicEffect(MagicEffect.PUFF, caster.CurrentPosition);
                    caster.AddAnonymousChat(ChatAnonymous.WHITE, "No target selected.");
                    return;
                }
            }
            //Constants.
            //Not the most efficient method but it is simple and works.
            int length = spell.SpellArea.GetLength(0);
            int width = spell.SpellArea.GetLength(1);

            Position startPos = new Position();
            startPos.x = (ushort)(spell.SpellCenter.x - (width / 2));
            startPos.y = (ushort)(spell.SpellCenter.y - (length / 2));
            startPos.z = spell.SpellCenter.z;
            Position local = new Position();

            List<Thing> things = new List<Thing>();
            for (int i = 0; i < length; i++) {
                for (int j = 0; j < width; j++) {
                    local.x = (ushort)(startPos.x + j);
                    local.y = (ushort)(startPos.y + i);
                    local.z = startPos.z;
                    if (map.GetTile(local) == null
                        /*|| !map.GetTile(local).CanMoveTo(caster)
                         * TODO: Finish*/) {
                        continue;
                    }

                    if (spell.SpellArea[i, j] &&
                        !map.GetTile(local).ContainsType(Constants.TYPE_BLOCKS_MAGIC)) {
                        ThingSet tSet = map.GetThingsInVicinity(local);
                        foreach (Thing thing in tSet.GetThings()) {
                            thing.AddEffect(spell.SpellEffect, local);
                            if (spell.HasDistanceType()) {
                                thing.AddShootEffect((byte)spell.DistanceEffect,
                                    caster.CurrentPosition, spell.SpellCenter);
                            }
                        }

                        List<Thing> localThings = map.GetTile(local).GetThings();

                        if (spell.Action != null) {
                            spell.Action.Invoke(world, local, localThings);
                        }

                        foreach (Thing thing in map.GetTile(local).GetThings()) {
                            things.Add(thing);
                        }
                    }
                }
            }

            foreach (Thing thing in things) {
                thing.AppendHandleDamage(spell.GetDamage(), caster, spell.Immunity, world, true);
            }

            //caster.NotifyOfSuccessfulCast(spell); TODO: Uncomment
        }
コード例 #28
0
 /// <summary>
 /// Process a player's set text (for example, write text on a scroll).
 /// </summary>
 /// <param name="player">The player doing the action.</param>
 /// <param name="world">A reference to the gameworld.</param>
 private void ProcessSetText(Player player, GameWorld world)
 {
     // TODO: Not implemented?
     uint windowID = netmsg.GetU32();
     string txt = netmsg.GetStringL();
 }
コード例 #29
0
ファイル: Respawn.cs プロジェクト: brewsterl/berserker
        /// <summary>
        /// TODO: Multiple spawns please.
        /// </summary>
        /// <param name="world"></param>
        public static void Load(GameWorld world)
        {
            string path = Config.GetDataPath() + "world/spawns.xml";
            XmlTextReader reader = new XmlTextReader(path);
            Respawn currentRespawn = null;
            while (reader.Read()) {
                switch (reader.NodeType) {
                    case XmlNodeType.Element:
                        while (reader.MoveToNextAttribute()) // Read attributes
                            {
                            if (reader.Name == "centerx") {
                                currentRespawn = new Respawn(world);
                                currentRespawn.CenterX = ushort.Parse(reader.Value);
                            } else if (reader.Name == "centery") {
                                currentRespawn.CenterY = ushort.Parse(reader.Value);
                            } else if (reader.Name == "centerz") {
                                currentRespawn.CenterZ = byte.Parse(reader.Value);
                            } else if (reader.Name == "radius") {
                                currentRespawn.Radius = int.Parse(reader.Value);
                            } else if (reader.Name == "name") {
                                currentRespawn.MonsterName = reader.Value;
                            } else if (reader.Name == "spawntime") {
                                if (currentRespawn.CanSpawn()) {
                                    currentRespawn.Spawn();
                                }
                                //currentRespawn.SpawnTime = 100 * int.Parse(reader.Value);
                            }
                        }
                        break;
                }
            }

            reader.Close();
        }
コード例 #30
0
        /// <summary>
        /// Proccess a player's change direction.
        /// </summary>
        /// <param name="player">The player doing the action.</param>
        /// <param name="world">A reference to the gameworld.</param>
        private void ProcessChangeDirection(Player player, GameWorld world)
        {
            byte rawDirection = netmsg.GetByte();

            //Validate direction
            if (!IsDirectionValid(rawDirection))
                return;

            Direction direction; //direction to move

            direction = (Direction)rawDirection;
            #if DEBUG
            Log.WriteDebug("In ProcessChangeDirection()");
            Log.WriteDebug("direction: " + direction);
            #endif
            world.HandleChangeDirection(player, direction);
        }