Example #1
0
        public void AddRewardUnits()
        {
            LogicCharacterData characterData = this.m_data.GetRewardCharacterData();

            if (characterData != null)
            {
                int characterCount = this.m_data.GetRewardCharacterCount();

                if (characterCount > 0)
                {
                    LogicClientAvatar    playerAvatar = this.m_level.GetPlayerAvatar();
                    LogicComponentFilter filter       = new LogicComponentFilter();

                    for (int i = 0; i < characterCount; i++)
                    {
                        filter.RemoveAllIgnoreObjects();

                        while (true)
                        {
                            LogicUnitStorageComponent component =
                                (LogicUnitStorageComponent)this.m_level.GetComponentManagerAt(this.m_level.GetVillageType()).GetClosestComponent(0, 0, filter);

                            if (component != null)
                            {
                                if (component.CanAddUnit(characterData))
                                {
                                    playerAvatar.CommodityCountChangeHelper(0, characterData, 1);
                                    component.AddUnit(characterData);

                                    if (this.m_level.GetState() == 1 || this.m_level.GetState() == 3)
                                    {
                                        if (component.GetParentListener() != null)
                                        {
                                            component.GetParentListener().ExtraCharacterAdded(characterData, null);
                                        }
                                    }

                                    break;
                                }

                                filter.AddIgnoreObject(component.GetParent());
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }