Пример #1
0
        /// <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();
        }
Пример #2
0
        /// <summary>
        /// Execute the specified command.
        /// </summary>
        /// <param name="world">A reference to the game world.</param>
        /// <param name="gameMap">A reference to the game map.</param>
        /// <param name="msg">The creature's message.</param>
        public static void ExecuteCommand(GameWorld world, Map gameMap,
            string msg, Creature creature)
        {
            string[] parameters = Regex.Split(msg, " ");

            commands[parameters[0].ToLower()].CommandMethod.
                Invoke(new object[] { world, gameMap, parameters, creature });
        }
Пример #3
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)
        {
            byte speakType = netmsg.GetByte();
            string reciever = null;
            ushort channelID = 0;
            if (speakType == Constants.SPEAK_PRIVATE_MSG ||
                speakType == Constants.SPEAK_RV_COUNSELLOR) {
                reciever = netmsg.GetStringL();
                return;
            } else if (speakType == Constants.SPEAK_CHANNEL_YELLOW) {
                channelID = netmsg.GetU16();
                return;
            }

            string msg = netmsg.GetStringL();
            Console.WriteLine("msg: " + msg);
            //Test for acceptable string length
            if (msg.Length > MAX_STRING_LENGTH) {
                return;
            }

            world.HandleChat(player, msg);
        }
Пример #4
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 ProcessWalkNorth(Player player, GameWorld world)
 {
     world.HandleManualWalk(player, Direction.NORTH);
 }
Пример #5
0
        /// <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
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
 public override bool HandleWalkAction(Creature creature, GameWorld world, WalkType type)
 {
     if (walkItems.ContainsKey(this.ItemID)) {
         return walkItems[ItemID](this, creature, world, type);
     }
     return true;
 }
Пример #8
0
 public void DoAction(GameWorld world)
 {
     world.HandlePush(player, posFrom, thingID, stackpos, posTo, count);
     player.CurrentDelayedAction = null;
 }
Пример #9
0
        public void InitCreatureCheck(GameWorld world)
        {
            AttackCheck = new AttackCheck();
            AttackCheck.CurrentCreature = this;
            AttackCheck.TimeInCS = 200; //2 seconds
            AttackCheck.World = world;
            world.AddEventInCS(AttackCheck.TimeInCS, AttackCheck.PerformCheck);

            FollowCheck = new FollowCheck();
            FollowCheck.CurrentCreature = this;
            FollowCheck.TimeInCS = 30; //Change based on certain things
            FollowCheck.World = world;
            world.AddEventInCS(FollowCheck.TimeInCS, FollowCheck.PerformCheck);

            TalkCheck = new TalkCheck();
            TalkCheck.CurrentCreature = this;
            TalkCheck.TimeInCS = 49; //50
            TalkCheck.World = world;
            world.AddEventInCS(TalkCheck.TimeInCS, TalkCheck.PerformCheck);

            SpellCheck = new SpellCheck();
            SpellCheck.CurrentCreature = this;
            SpellCheck.TimeInCS = 51; //50
            SpellCheck.World = world;
            world.AddEventInCS(SpellCheck.TimeInCS, SpellCheck.PerformCheck);
        }
Пример #10
0
 /// <summary>
 /// Construct this object.
 /// </summary>
 /// <param name="gameMap">Reference to the game map.</param>
 public MovingSystem(Map gameMap, GameWorld gameWorld)
 {
     map   = gameMap;
     world = gameWorld;
 }
Пример #11
0
        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 cyclops.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
            {
                DynamicCompile compiler            = new DynamicCompile();
                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();
        }
Пример #12
0
 public abstract void AppendHandlePush(Player player, Position posFrom, ushort thingID,
                                       byte stackpos, Position posTo, byte count, GameWorld world);
Пример #13
0
 public virtual void AppendHandleDamage(int dmgAmt, Creature attacker, ImmunityType type,
                                        GameWorld world, bool magic)
 {
 }
Пример #14
0
 /// <summary>
 /// 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="world">A reference to the game world.</param>
 /// <returns></returns>
 public virtual bool HandleWalkAction(Creature creature, GameWorld world, WalkType type)
 {
     return(true);
 }
Пример #15
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 ProcessWalkWest(Player player, GameWorld world)
 {
     world.HandleManualWalk(player, Direction.WEST);
 }
Пример #16
0
 public override void AppendHandleDamage(int dmgAmt, Creature attacker, ImmunityType type,
     GameWorld world, bool magic)
 {
     world.AppendAddDamage(attacker, this, dmgAmt, type, magic);
 }
Пример #17
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)
 {
     byte type = netmsg.GetByte();
     uint windowID = netmsg.GetU32();
     string txt = netmsg.GetStringL();
 }
Пример #18
0
 public virtual void UseThingWith(Player user, Position posWith, GameWorld world,
                                  byte stackposWith)
 {
 }
Пример #19
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);
 }
Пример #20
0
 public void DoAction(GameWorld world)
 {
     world.HandleUseItem(player, itemType, pos, itemID, stackpos);
     player.CurrentDelayedAction = null;
 }
Пример #21
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);
 }
Пример #22
0
 /// 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);
     }
 }
Пример #23
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)) {
                if (header == 0xFF) { //Logout header
                    player.Logout();
                    return false;
                }
            } else if (messageDecoder[header] == null) {
                PrintHeader(netmsg, header);
            } else {
                messageDecoder[header].Invoke(player, world);
            }
            return true;
        }
Пример #24
0
 public Respawn(GameWorld gameWorld)
 {
     world = gameWorld;
 }
Пример #25
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);
 }
Пример #26
0
 /// <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);
 }
Пример #27
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);
 }
Пример #28
0
 //public abstract bool ProcessNextMessage(Player player, GameWorld world);
 /// <summary>
 /// Stars listening asynchronously and handles the messages as needed. 
 /// </summary>
 public virtual void StartReceiving(GameWorld world, Player player)
 {
 }
Пример #29
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);
        }
Пример #30
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 ProcessWalkSouth(Player player, GameWorld world)
 {
     world.HandleManualWalk(player, Direction.SOUTH);
 }
Пример #31
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);
 }
Пример #32
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)
 {
     uint windowID = netmsg.GetU32();
     string txt = netmsg.GetStringL();
 }
Пример #33
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);
            }*/
        }
Пример #34
0
 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);
 }
Пример #35
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);*/
        }
Пример #36
0
 /// <summary>
 /// Construct this object.
 /// </summary>
 /// <param name="gameMap">Reference to the game map.</param>
 public MovingSystem(Map gameMap, GameWorld gameWorld)
 {
     map = gameMap;
     world = gameWorld;
 }
Пример #37
0
 /// <summary>
 /// Use the thing.
 /// </summary>
 /// <param name="user">The player using the thing.</param>
 public virtual void UseThing(Player user, GameWorld world)
 {
 }