public override async void Process(Level level)
        {
            try
            {
                Alliance a = await ObjectManager.GetAlliance(level.GetPlayerAvatar().GetAllianceId());

                StreamEntry stream  = a.GetChatMessages().Find(c => c.GetId() == MessageID);
                Level       _Sender = await ResourcesManager.GetPlayer(stream.GetSenderId());

                int upcomingspace = stream.m_vDonatedTroop + Troop.GetHousingSpace();

                if (upcomingspace <= stream.m_vMaxTroop)
                {
                    DonateAllianceUnitCommand _Donate = new DonateAllianceUnitCommand();
                    _Donate.SetMessageID(MessageID);
                    _Donate.Tick(level);
                    _Donate.SetUnit(Troop);

                    DonatedAllianceUnitCommand _Donated = new DonatedAllianceUnitCommand();
                    _Donated.Tick(_Sender);
                    _Donated.SetDonator(level.GetPlayerAvatar().GetAvatarName());
                    _Donated.SetUnitID(Troop.GetGlobalID());
                    _Donated.SetUnitLevel(level.GetPlayerAvatar().GetUnitUpgradeLevel(Troop));

                    AvailableServerCommandMessage availableServerCommandMessage = new AvailableServerCommandMessage(level.GetClient());
                    availableServerCommandMessage.SetCommandId(4);
                    availableServerCommandMessage.SetCommand(_Donate);

                    AvailableServerCommandMessage ravailableServerCommandMessage = new AvailableServerCommandMessage(_Sender.GetClient());
                    ravailableServerCommandMessage.SetCommandId(5);
                    ravailableServerCommandMessage.SetCommand(_Donated);

                    StreamEntry _Stream         = a.GetChatMessages().Find(c => c.GetId() == MessageID);
                    Level       _PreviousPlayer = await ResourcesManager.GetPlayer(_Stream.GetSenderId());

                    ClientAvatar _PreviousPlayerAvatar = _PreviousPlayer.GetPlayerAvatar();
                    _Stream.AddDonatedTroop(level.GetPlayerAvatar().GetId(), Troop.GetGlobalID(), 1, level.GetPlayerAvatar().GetUnitUpgradeLevel(Troop));
                    int _Capicity = Troop.GetHousingSpace();
                    _Stream.AddUsedCapicity(_Capicity);
                    _PreviousPlayerAvatar.SetAllianceCastleUsedCapacity(_PreviousPlayerAvatar.GetAllianceCastleUsedCapacity() + _Capicity);
                    _PreviousPlayerAvatar.AddAllianceTroop(level.GetPlayerAvatar().GetId(), Troop.GetGlobalID(), 1, level.GetPlayerAvatar().GetUnitUpgradeLevel(Troop));

                    //PacketProcessor.Send(availableServerCommandMessage);
                    if (ResourcesManager.IsPlayerOnline(_Sender))
                    {
                        PacketProcessor.Send(ravailableServerCommandMessage);
                    }

                    foreach (AllianceMemberEntry op in a.GetAllianceMembers())
                    {
                        Level player = await ResourcesManager.GetPlayer(op.GetAvatarId());

                        if (player.GetClient() != null)
                        {
                            AllianceStreamEntryMessage c = new AllianceStreamEntryMessage(player.GetClient());
                            c.SetStreamEntry(_Stream);
                            PacketProcessor.Send(c);
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }
Ejemplo n.º 2
0
        internal override async void Process()
        {
            try
            {
                /*if (this.BuyTroop >= 1)
                 * {
                 *  this.Device.Player.Avatar.SetDiamonds(this.Device.Player.Avatar.m_vCurrentGems - Troop.GetHousingSpace());
                 * }*/

                Alliance    a       = ObjectManager.GetAlliance(this.Device.Player.Avatar.AllianceId);
                StreamEntry _Stream = a.m_vChatMessages.Find(c => c.ID == MessageID);
                Level       _Sender = await ResourcesManager.GetPlayer(_Stream.SenderID);

                int upcomingspace = _Stream.m_vDonatedTroop + Troop.GetHousingSpace();

                if (upcomingspace <= _Stream.m_vMaxTroop)
                {
                    DonatedAllianceUnitCommand _Donated = new DonatedAllianceUnitCommand(this.Device);
                    _Donated.Tick(_Sender);
                    _Donated.MessageID = this.MessageID;
                    _Donated.TroopID   = Troop.GetGlobalID();

                    new AvailableServerCommandMessage(this.Device, _Donated.Handle()).Send();

                    ReceivedAllianceUnitCommand _Received = new ReceivedAllianceUnitCommand(this.Device);
                    _Received.Donator_Name = this.Device.Player.Avatar.AvatarName;
                    _Received.TroopID      = this.Troop.GetGlobalID();
                    _Received.Troop_Level  = this.Device.Player.Avatar.GetUnitUpgradeLevel(Troop);

                    new AvailableServerCommandMessage(_Sender.Client, _Received).Send();

                    Level _PreviousPlayer = await ResourcesManager.GetPlayer(_Stream.SenderID);

                    ClientAvatar _PreviousPlayerAvatar = _PreviousPlayer.Avatar;
                    _Stream.AddDonatedTroop(this.Device.Player.Avatar.UserId, Troop.GetGlobalID(), 1, this.Device.Player.Avatar.GetUnitUpgradeLevel(Troop));

                    int _Capicity = Troop.GetHousingSpace();
                    _Stream.AddUsedCapicity(_Capicity);
                    _PreviousPlayerAvatar.SetAllianceCastleUsedCapacity(_PreviousPlayerAvatar.GetAllianceCastleUsedCapacity() + _Capicity);
                    _PreviousPlayerAvatar.AddAllianceTroop(this.Device.Player.Avatar.UserId, Troop.GetGlobalID(), 1, this.Device.Player.Avatar.GetUnitUpgradeLevel(Troop));

                    this.Device.Player.Avatar.m_vDonated++;
                    _Sender.Avatar.m_vReceived++;


                    foreach (AllianceMemberEntry op in a.GetAllianceMembers())
                    {
                        Level player = await ResourcesManager.GetPlayer(op.AvatarId);

                        if (player.Client != null)
                        {
                            new AllianceStreamEntryMessage(player.Client)
                            {
                                StreamEntry = _Stream
                            }.Send();
                        }
                    }
                }
            }
            catch (Exception)
            {
            }
        }