Beispiel #1
0
 public void HandlePush(Player player, Position posFrom, ushort thingID,
                        byte stackpos, Position posTo, byte count, Creature creatureMoved)
 {
     HandlePush(player, posFrom, thingID, stackpos, posTo, count);
     creatureToMove = creatureMoved;
     if (!creatureMoved.IsOfType(Constants.TYPE_MOVEABLE) ||
         map.GetTile(posTo) == null)
     {
         return;
     }
     if (map.GetTile(posTo).ContainsType(Constants.TYPE_BLOCKS_AUTO_WALK) ||
         !creatureToMove.IsNextTo(posTo) || !player.IsNextTo(posFrom))
     {
         return;
     }
     world.HandleMove(creatureMoved, posTo, creatureToMove.CurrentDirection);
 }
Beispiel #2
0
 public void HandlePush(Player player, Position posFrom, ushort thingID,
     byte stackpos, Position posTo, byte count, Creature creatureMoved)
 {
     HandlePush(player, posFrom, thingID, stackpos, posTo, count);
     creatureToMove = creatureMoved;
     if (!creatureMoved.IsOfType(Constants.TYPE_MOVEABLE)
         || map.GetTile(posTo) == null) {
         return;
     }
     if (map.GetTile(posTo).ContainsType(Constants.TYPE_BLOCKS_AUTO_WALK)
         || !creatureToMove.IsNextTo(posTo) || !player.IsNextTo(posFrom)) {
         return;
     }
     world.HandleMove(creatureMoved, posTo, creatureToMove.CurrentDirection);
 }
Beispiel #3
0
        //One huge ugly method. TODO: Split it up.
        public virtual void HandleAttackCheck(Creature attacker, Creature attacked)
        {
            lock (lockThis) {
                if (attacker == attacked) {
                    //throw new Exception("Attacker == attacked in HandleAttackCheck()");
                    return;
                }

                if (attacked == null || !attacked.LogedIn) {
                    attacker.SetCreatureAttacking(null);
                    return;
                }

                if (attacked.CurrentPosition == null) {
                    throw new Exception("Invalid condition in HandleAttackCheck()");
                }

                if (attacked.CurrentHP == 0) {
                    throw new Exception("Attacked is already dead in HandleAttack()");
                }

                bool usingDistance = attacker.UsingDistance();
                DistanceType shootEffect = DistanceType.EFFECT_NONE;
                if (usingDistance) {
                    if (attacker.GetAmmo() == 0) {
                        return;
                    } else {
                        shootEffect = attacker.GetDistanceType();
                    }
                } else if (!usingDistance &&
                    !attacker.IsNextTo(attacked.CurrentPosition)) {
                    return;
                }

                ThingSet tSet = gameMap.GetThingsInVicinity(attacker.CurrentPosition);
                gameMap.GetThingsInVicinity(attacked.CurrentPosition, tSet);

                if (shootEffect != DistanceType.EFFECT_NONE) {
                    AddShootEffect(shootEffect, attacker.CurrentPosition,
                        attacked.CurrentPosition, tSet);
                }

                int dmg = attacked.GetDamageAmt(attacker);
                if (dmg == Constants.PUFF) {
                    AddMagicEffect(MagicEffect.PUFF, attacked.CurrentPosition);
                    dmg = 0;
                } else if (dmg == Constants.SPARK) {
                    AddMagicEffect(MagicEffect.BLOCKHIT, attacked.CurrentPosition);
                    dmg = 0;
                } else {
                    AddMagicEffect(MagicEffect.DRAW_BLOOD, attacked.CurrentPosition);
                }
                AppendAddDamage(attacker, attacked, dmg, ImmunityType.IMMUNE_PHYSICAL, false);
                SendProtocolMessages();
            }
        }
Beispiel #4
0
        public void AppendHandleMove(Creature creature, Position newPos, Direction direction, bool validateMove)
        {
            lock (lockThis) {
                Position oldPos = creature.CurrentPosition;
                Tile oldTile = gameMap.GetTile(oldPos);
                Tile newTile = gameMap.GetTile(newPos);
                if (validateMove) {
                    if (newTile == null || newTile.ContainsType(Constants.TYPE_BLOCKING)) {
                        return;
                    }
                }

                foreach (Thing thing in oldTile.GetThings()) {
                    bool proceed = thing.HandleWalkAction(creature, this, WalkType.WALK_OFF);
                    if (!proceed) {
                        return;
                    }
                }
                foreach (Thing thing in newTile.GetThings()) {
                    bool proceed = thing.HandleWalkAction(creature, this, WalkType.WALK_ON);
                    if (!proceed) {
                        return;
                    }
                }

                if (creature.IsNextTo(newPos)) {
                    //TODO: Finish coding speed
                    int speed = GetGroundSpeed(creature.CurrentPosition);
                    int duration = (100 * 90 /*speed*/) / (creature.GetSpeed());
                    creature.LastWalk.SetTimeInCS((uint)duration);

                    if (!creature.LastWalk.Elapsed()) {
                        return;
                    }

                    Position oldPosClone = oldPos.Clone();
                    if (oldPos.y > newPos.y) {
                        direction = Direction.NORTH;
                        oldPosClone.y--;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    } else if (oldPos.y < newPos.y) {
                        direction = Direction.SOUTH;
                        oldPosClone.y++;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    }
                    if (oldPos.x < newPos.x) {
                        direction = Direction.EAST;
                        oldPosClone.x++;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    } else if (oldPos.x > newPos.x) {
                        direction = Direction.WEST;
                        oldPosClone.x--;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    }
                }
                ThingSet tSet = gameMap.GetThingsInVicinity(creature.CurrentPosition);
                byte oldStackPos = gameMap.GetStackPosition(creature, oldPos);
                gameMap.MoveThing(creature, oldPos, newPos);
                creature.CurrentDirection = direction;
                byte newStackPos = gameMap.GetStackPosition(creature, newPos);
                gameMap.GetThingsInVicinity(newPos, tSet);
                creature.HandleMove();

                foreach (Thing thing in tSet.GetThings()) {
                    thing.AddCreatureMove(direction, creature, oldPos, newPos,
                        oldStackPos, newStackPos);
                }

                if (!creature.IsNextTo(oldPos)) {
                    creature.AddTeleport(gameMap);
                }
            }
        }
Beispiel #5
0
        //One huge ugly method. TODO: Split it up.
        public virtual void HandleAttackCheck(Creature attacker, Creature attacked)
        {
            lock (lockThis) {
                if (attacker == attacked)
                {
                    //throw new Exception("Attacker == attacked in HandleAttackCheck()");
                    return;
                }

                if (attacked == null || !attacked.LogedIn)
                {
                    attacker.SetCreatureAttacking(null);
                    return;
                }

                if (attacked.CurrentPosition == null)
                {
                    throw new Exception("Invalid condition in HandleAttackCheck()");
                }

                if (attacked.CurrentHP == 0)
                {
                    throw new Exception("Attacked is already dead in HandleAttack()");
                }

                bool         usingDistance = attacker.UsingDistance();
                DistanceType shootEffect   = DistanceType.EFFECT_NONE;
                if (usingDistance)
                {
                    if (attacker.GetAmmo() == 0)
                    {
                        return;
                    }
                    else
                    {
                        shootEffect = attacker.GetDistanceType();
                    }
                }
                else if (!usingDistance &&
                         !attacker.IsNextTo(attacked.CurrentPosition))
                {
                    return;
                }

                ThingSet tSet = gameMap.GetThingsInVicinity(attacker.CurrentPosition);
                gameMap.GetThingsInVicinity(attacked.CurrentPosition, tSet);

                if (shootEffect != DistanceType.EFFECT_NONE)
                {
                    AddShootEffect(shootEffect, attacker.CurrentPosition,
                                   attacked.CurrentPosition, tSet);
                }

                int dmg = attacked.GetDamageAmt(attacker);
                if (dmg == Constants.PUFF)
                {
                    AddMagicEffect(MagicEffect.PUFF, attacked.CurrentPosition);
                    dmg = 0;
                }
                else if (dmg == Constants.SPARK)
                {
                    AddMagicEffect(MagicEffect.BLOCKHIT, attacked.CurrentPosition);
                    dmg = 0;
                }
                else
                {
                    AddMagicEffect(MagicEffect.DRAW_BLOOD, attacked.CurrentPosition);
                }
                AppendAddDamage(attacker, attacked, dmg, ImmunityType.IMMUNE_PHYSICAL, false);
                SendProtocolMessages();
            }
        }
Beispiel #6
0
        public void AppendHandleMove(Creature creature, Position newPos, Direction direction, bool validateMove)
        {
            lock (lockThis) {
                Position oldPos  = creature.CurrentPosition;
                Tile     oldTile = gameMap.GetTile(oldPos);
                Tile     newTile = gameMap.GetTile(newPos);
                if (validateMove)
                {
                    if (newTile == null || newTile.ContainsType(Constants.TYPE_BLOCKING))
                    {
                        return;
                    }
                }

                foreach (Thing thing in oldTile.GetThings())
                {
                    bool proceed = thing.HandleWalkAction(creature, this, WalkType.WALK_OFF);
                    if (!proceed)
                    {
                        return;
                    }
                }
                foreach (Thing thing in newTile.GetThings())
                {
                    bool proceed = thing.HandleWalkAction(creature, this, WalkType.WALK_ON);
                    if (!proceed)
                    {
                        return;
                    }
                }

                if (creature.IsNextTo(newPos))
                {
                    //TODO: Finish coding speed
                    int speed    = GetGroundSpeed(creature.CurrentPosition);
                    int duration = (100 * 90 /*speed*/) / (creature.GetSpeed());
                    creature.LastWalk.SetTimeInCS((uint)duration);

                    if (!creature.LastWalk.Elapsed())
                    {
                        return;
                    }

                    Position oldPosClone = oldPos.Clone();
                    if (oldPos.y > newPos.y)
                    {
                        direction = Direction.NORTH;
                        oldPosClone.y--;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    }
                    else if (oldPos.y < newPos.y)
                    {
                        direction = Direction.SOUTH;
                        oldPosClone.y++;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    }
                    if (oldPos.x < newPos.x)
                    {
                        direction = Direction.EAST;
                        oldPosClone.x++;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    }
                    else if (oldPos.x > newPos.x)
                    {
                        direction = Direction.WEST;
                        oldPosClone.x--;
                        creature.AddScreenMoveByOne(direction, oldPos, oldPosClone, gameMap);
                    }
                }
                ThingSet tSet        = gameMap.GetThingsInVicinity(creature.CurrentPosition);
                byte     oldStackPos = gameMap.GetStackPosition(creature, oldPos);
                gameMap.MoveThing(creature, oldPos, newPos);
                creature.CurrentDirection = direction;
                byte newStackPos = gameMap.GetStackPosition(creature, newPos);
                gameMap.GetThingsInVicinity(newPos, tSet);
                creature.HandleMove();

                foreach (Thing thing in tSet.GetThings())
                {
                    thing.AddCreatureMove(direction, creature, oldPos, newPos,
                                          oldStackPos, newStackPos);
                }

                if (!creature.IsNextTo(oldPos))
                {
                    creature.AddTeleport(gameMap);
                }
            }
        }