예제 #1
0
        /// <summary>
        /// Move the specified thing to the ground.
        /// </summary>
        /// <param name="thingToMove">Thing to move.</param>
        /// <param name="posTo">Position to move to.</param>
        /// <param name="thingsPrepared">A reference to the things
        /// already prepared.</param>
        private void MoveToGround()
        {
            Thing topThing = map.GetTopThing(posTo);
            Item  topItem  = null;

            if (topThing.IsOfType(Constants.TYPE_STACKABLE))
            {
                topItem = (Item)topThing;
            }

            bool stackable = false;
            bool addItem   = true;

            if (topItem != null && itemToMove != null &&
                topItem.ItemID == itemToMove.ItemID)      //Both stackable items of same type
            {
                stackable = true;
                if (topItem.Count + itemToMove.Count > MAX_STACK_COUNT)
                {
                    byte countRemainder = (byte)(MAX_STACK_COUNT - topItem.Count);
                    topItem.Count    += countRemainder;
                    itemToMove.Count -= countRemainder;
                }
                else
                {
                    topItem.Count += itemToMove.Count;
                    addItem        = false;
                }
            }

            ThingSet tSet     = map.GetThingsInVicinity(posTo);
            byte     stackpos = map.GetStackPosition(itemToMove, posTo);

            if (stackable)
            {
                foreach (Thing thing in tSet.GetThings())
                {
                    thing.UpdateItem(posTo, topItem,
                                     map.GetStackPosition(topItem, posTo));
                }
            }

            if (addItem)
            {
                map.AddThing(itemToMove, posTo);

                foreach (Thing thing in tSet.GetThings())
                {
                    thing.AddThingToGround(itemToMove, posTo,
                                           map.GetStackPosition(itemToMove, posTo));
                }
            }
        }
예제 #2
0
파일: respawn.cs 프로젝트: Wirless/cyclops
        //TODO: Completely rework this method... it currently sucks
        //A LOT... i mean it!
        public void CheckForRespawn()
        {
            Position pos     = new Position(CenterX, CenterY, CenterZ);
            Monster  monster = Monster.CreateMonster(MonsterName);

            if (monster != null && world.GetGameMap().GetTile(pos) != null)
            {
                world.AppendAddMonster(monster, pos);
            }
            return;

            Map      map  = world.GetGameMap();
            ThingSet tSet = map.GetThingsInVicinity(pos);

            //Monster monster = Monster.CreateMonster(MonsterName);
            if (monster == null)
            {
                return;
            }

            if (map.GetTile(pos) != null &&
                !map.TileContainsType(pos, Constants.TYPE_BLOCKS_AUTO_WALK))
            {
                bool canRespawn = true;
                foreach (Thing thing in tSet.GetThings())
                {
                    if (thing is Player)       //TODO: FIX this crap
                    {
                        canRespawn = false;
                    }
                }
                if (canRespawn)
                {
                    world.SendAddMonster(monster, pos);
                }
            }
            else
            {
                return;
            }

            //  if (map.GetTile(pos) != null &&
            // !map.TileContainsType(pos, Constants.TYPE_BLOCKS_AUTO_WALK)) {
            // Console.WriteLine("x: " + x++);
            //world.SendAddMonster(monster, pos);
            // }

            world.AddEventInCS(SpawnTime, CheckForRespawn);
        }
예제 #3
0
        /// <summary>
        /// Handle a message from a creature.
        /// </summary>
        /// <param name="creature">The creature sending the message.</param>
        /// <param name="msg">The message sent.</param>
        public void HandleChat(Creature creature, string msg)
        {
            ThingSet tSet = new ThingSet();

            if (msg.StartsWith(PRIVATE_MSG_INDICATOR))
            {
                HandlePrivateMessage(creature, msg);
            }
            else if (msg.StartsWith(MSG_QUANTIFIER))
            {
                HandleQuantifiedMessage(creature, msg, tSet);
            }
            else
            {
                tSet = gameMap.GetThingsInVicinity(creature.CurrentPosition, true);
                HandleLocalChat(creature.GetChatType(), tSet, msg, creature);
            }
        }
예제 #4
0
파일: monster.cs 프로젝트: Wirless/cyclops
 public override void AppendNotifyOfDeath(Item corpse, Map gameMap)
 {
     AddLoot(corpse);
     gameMap.GetThingsInVicinity(CurrentPosition);
     //Give experience to all creatures who attacked
     foreach (AttackersInformation atkInfo in attackersInfoList)
     {
         if (atkInfo.Attacker.LogedIn)
         {
             uint xp = FigureOutExperienceAmt(atkInfo.DamageByCreature, totalDamageDealt);
             atkInfo.Attacker.AddExperienceGain(xp * Config.GetXPRate());
         }
     }
     if (IsSummon())
     {
         Master.RemoveSummon(this);
     }
     World.AppendRemoveMonster(this);
 }
예제 #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 AppendNotifyOfDeath(Item corpse, Map gameMap)
 {
     AddLoot(corpse);
     gameMap.GetThingsInVicinity(CurrentPosition);
     //Give experience to all creatures who attacked
     foreach (AttackersInformation atkInfo in attackersInfoList) {
             if (atkInfo.Attacker.LogedIn) {
                 uint xp = FigureOutExperienceAmt(atkInfo.DamageByCreature, totalDamageDealt);
                 atkInfo.Attacker.AddExperienceGain(xp * Config.GetXPRate());
             }
     }
     if (IsSummon()) {
         Master.RemoveSummon(this);
     }
     World.AppendRemoveMonster(this);
 }
예제 #7
0
        private void AppendAddCreature(Creature creature, Position position)
        {
            position = gameMap.GetFreePosition(position, creature);
            ThingSet tSet = gameMap.GetThingsInVicinity(position);

            AddCachedCreature(creature, position);
            creature.InitCreatureCheck(this);
            byte stackpos = gameMap.GetStackPosition(creature, position);

            foreach (Thing thing in tSet.GetThings())
            {
                thing.AddScreenCreature(creature, position, stackpos);
            }
        }