Ejemplo n.º 1
0
        private void GateRepair(Session session, Packet packet)
        {
            uint strongholdId;

            try
            {
                strongholdId = packet.GetUInt32();
            }
            catch (Exception)
            {
                ReplyError(session, packet, Error.Unexpected);
                return;
            }

            if (session.Player.Tribesman == null)
            {
                ReplyError(session, packet, Error.TribeIsNull);
                return;
            }
            var tribe = session.Player.Tribesman.Tribe;

            IStronghold stronghold;

            if (!strongholdManager.TryGetStronghold(strongholdId, out stronghold))
            {
                ReplyError(session, packet, Error.StrongholdNotFound);
                return;
            }

            locker.Lock(tribe, stronghold).Do(() =>
            {
                if (!stronghold.BelongsTo(tribe))
                {
                    ReplyError(session, packet, Error.StrongholdNotOccupied);
                    return;
                }

                if (!tribe.HasRight(session.Player.PlayerId, TribePermission.Repair))
                {
                    ReplyError(session, packet, Error.TribesmanNotAuthorized);
                    return;
                }

                var result = strongholdManager.RepairGate(stronghold);
                ReplyWithResult(session, packet, result);
            });
        }