Ejemplo n.º 1
0
        public virtual void RemoveGameAsset(AbstractGameAsset asset)
        {
            if (asset.Type != ChosenGameAssetTemplate.Type)
            {
                throw new Exception(
                          string.Format(
                              "Tried to remove game asset {0} from a buy point which has chosen {1}",
                              asset, ChosenGameAssetTemplate.Type));
            }

            lock (GameAssets)
            {
                if (GameAssets.ContainsKey(asset.Uuid))
                {
                    GameAssets.Remove(asset.Uuid);

                    switch (asset.Type)
                    {
                    case AbstractGameAssetType.Crops:
                        Cropss.Remove((Crops)asset);
                        break;

                    case AbstractGameAssetType.Houses:
                        Housess.Remove((Houses)asset);
                        break;

                    case AbstractGameAssetType.Factory:
                        Factories.Remove((Factory)asset);
                        break;

                    default:
                        throw new Exception(string.Format("Unrecognized asset {0}", asset));
                    }
                }
                else
                {
                    m_log.WarnFormat(
                        "[WATER WARS]: Request to remove asset {0} but it wasn't in buy point {1}", asset, this);
                }

                if (GameAssets.Count == 0)
                {
                    ChosenGameAssetTemplate = AbstractGameAsset.None;
                }

                lock (Game.GameAssets)
                    Game.GameAssets.Remove(asset.Uuid);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Remove all game assets from the parcel
        /// </summary>
        public virtual void RemoveAllGameAssets()
        {
            lock (GameAssets)
            {
                lock (Game.GameAssets)
                    foreach (AbstractGameAsset ga in GameAssets.Values)
                    {
                        Game.GameAssets.Remove(ga.Uuid);
                    }

                GameAssets.Clear();
                Cropss.Clear();
                Housess.Clear();
                Factories.Clear();
                ChosenGameAssetTemplate = AbstractGameAsset.None;
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add a game asset.
        /// </summary>
        /// Will throw an exception if the asset is different from the asset type chosen for this buy point.
        /// <param name="asset"></param>
        public virtual void AddGameAsset(AbstractGameAsset asset)
        {
            if (ChosenGameAssetTemplate != AbstractGameAsset.None && asset.Type != ChosenGameAssetTemplate.Type)
            {
                throw new Exception(
                          string.Format(
                              "Tried to add game asset {0} to a buy point which has chosen {1}", asset, ChosenGameAssetTemplate.Type));
            }

            lock (GameAssets)
            {
                GameAssets.Add(asset.Uuid, asset);

                switch (asset.Type)
                {
                case AbstractGameAssetType.Crops:
                    ChosenGameAssetTemplate = Crops.Template;
                    Cropss.Add((Crops)asset);
                    break;

                case AbstractGameAssetType.Houses:
                    ChosenGameAssetTemplate = Houses.Template;
                    Housess.Add((Houses)asset);
                    break;

                case AbstractGameAssetType.Factory:
                    ChosenGameAssetTemplate = Factory.Template;
                    Factories.Add((Factory)asset);
                    break;

                default:
                    throw new Exception(string.Format("Unrecognized asset {0}", asset));
                }

                lock (Game.GameAssets)
                    Game.GameAssets[asset.Uuid] = asset;
            }
        }