Example #1
0
    private void EditItemGUI()
    {
        EditorGUI.indentLevel = 1;
        EditorGUILayout.LabelField("Edit Item", EditorStyles.boldLabel);
        EditorGUI.indentLevel = 2;
        string[] values       = ItemEntities.items.Values.Select(x => x.Name).ToArray <string>();
        int      index        = values.ToList().IndexOf(editItem.Name);
        int      currentIndex = EditorGUILayout.Popup("Select Item", index, values);
        var      icon         = EditorGUILayout.TextField("Icon:", editItem.icon);
        var      sprite       = EditorGUILayout.TextField("Sprite:", editItem.sprite);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(30);
        if (GUILayout.Button("Edit Item"))
        {
            ResourcesLoader.SaveObject("Assets/Resources/Entities/Items/", editItem.name, editItem);
            ItemEntities.Update();
        }
        EditorGUILayout.EndHorizontal();
        EditorGUI.indentLevel = 1;

        if (GUI.changed)
        {
            string nName = values[currentIndex];
            if (nName != editItem.Name)
            {
                editItem = ItemEntities.items[nName];
            }
            else
            {
                editItem.icon   = icon;
                editItem.sprite = sprite;
            }
        }
    }
Example #2
0
        //新增一筆Product,使用ProductId
        public bool AddProduct(int ProductId)
        {
            var findItem = this.cartItems
                           .Where(s => s.Id == ProductId)
                           .Select(s => s)
                           .FirstOrDefault();

            //判斷相同Id的CartItem是否已經存在購物車內
            if (findItem == default(Models.Cart.CartItem))
            {   //不存在購物車內,則新增一筆
                using (Models.ItemEntities db = new ItemEntities())
                {
                    var product = (from s in db.Products
                                   where s.Id == ProductId
                                   select s).FirstOrDefault();
                    if (product != default(Models.Product))
                    {
                        this.AddProduct(product);
                    }
                }
            }
            else
            {   //存在購物車內,則將商品數量累加
                findItem.Quantity += 1;
            }
            return(true);
        }
Example #3
0
    private void AddItemGUI()
    {
        EditorGUI.indentLevel = 1;

        EditorGUILayout.LabelField("Add Item", EditorStyles.boldLabel);

        EditorGUI.indentLevel = 2;

        var name   = EditorGUILayout.TextField("Name:", addItem.name);
        var icon   = EditorGUILayout.TextField("Icon:", addItem.icon);
        var sprite = EditorGUILayout.TextField("Sprite:", addItem.sprite);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Space(30);
        if (GUILayout.Button("Add Item"))
        {
            ResourcesLoader.SaveObject("Assets/Resources/Entities/Items/", addItem.name, addItem);
            ItemEntities.Update();
        }
        EditorGUILayout.EndHorizontal();
        EditorGUI.indentLevel = 1;

        if (GUI.changed)
        {
            addItem.name   = name;
            addItem.icon   = icon;
            addItem.sprite = sprite;
        }
    }
Example #4
0
        public Entity GetEntity(int id)
        {
            Player ret1;

            if (Players.TryGetValue(id, out ret1))
            {
                return(ret1);
            }
            Enemy ret2;

            if (Enemies.TryGetValue(id, out ret2))
            {
                return(ret2);
            }
            StaticObject ret3;

            if (StaticObjects.TryGetValue(id, out ret3))
            {
                return(ret3);
            }
            ItemEntity ret4;

            if (ItemEntities.TryGetValue(id, out ret4))
            {
                return(ret4);
            }
            return(null);
        }
Example #5
0
 public override void OnInspectorGUI()
 {
     if (GUILayout.Button("Update Item Entities"))
     {
         ItemEntities.Update();
     }
     AddItemGUI();
     EditItemGUI();
 }
Example #6
0
 private void Awake()
 {
     baseScript = GetComponent <SimpleObject>();
     if (drop == null)
     {
         ItemEntities.Init();
         drop = new ItemStack(ItemEntities.items.Values.First());
     }
 }
Example #7
0
        public virtual int EnterWorld(Entity entity)
        {
            if (entity is Player)
            {
                entity.Id = GetNextEntityId();
                entity.Init(this);
                Players.TryAdd(entity.Id, entity as Player);
                PlayersCollision.Insert(entity);
                SpawnEntity(entity);
            }
            else if (entity is Enemy)
            {
                entity.Id = GetNextEntityId();
                entity.Init(this);
                Enemies.TryAdd(entity.Id, entity as Enemy);
                EnemiesCollision.Insert(entity);
                if (entity.ObjectDesc.Quest)
                {
                    Quests.TryAdd(entity.Id, entity as Enemy);
                }

                if (entity.isPet)
                {
                    Pets.TryAdd(entity.Id, entity);
                }
            }
            else if (entity is Projectile)
            {
                entity.Init(this);
                var prj = entity as Projectile;
                Projectiles[new Tuple <int, byte>(prj.ProjectileOwner.Self.Id, prj.ProjectileId)] = prj;
            }
            else if (entity is StaticObject)
            {
                entity.Id = GetNextEntityId();
                entity.Init(this);
                StaticObjects.TryAdd(entity.Id, entity as StaticObject);
                if (entity is Decoy)
                {
                    PlayersCollision.Insert(entity);
                }
                else
                {
                    EnemiesCollision.Insert(entity);
                }
            }
            else if (entity is ItemEntity)
            {
                entity.Id = GetNextEntityId();
                entity.Init(this);
                ItemEntities.TryAdd(entity.Id, entity as ItemEntity);
                EnemiesCollision.Insert(entity);
            }
            return(entity.Id);
        }
Example #8
0
 public void Dispose()
 {
     Players.Clear();
     Enemies.Clear();
     Quests.Clear();
     Pets.Clear();
     Projectiles.Clear();
     StaticObjects.Clear();
     ItemEntities.Clear();
     Timers.Clear();
 }
Example #9
0
 public virtual void LeaveWorld(Entity entity)
 {
     if (entity is Player)
     {
         Player dummy;
         Players.TryRemove(entity.Id, out dummy);
         PlayersCollision.Remove(entity);
     }
     else if (entity is Enemy)
     {
         Enemy dummy;
         Enemies.TryRemove(entity.Id, out dummy);
         EnemiesCollision.Remove(entity);
         if (entity.ObjectDesc.Quest)
         {
             Quests.TryRemove(entity.Id, out dummy);
         }
         if (entity.isPet)
         {
             Entity dummy2;
             Pets.TryRemove(entity.Id, out dummy2);
         }
     }
     else if (entity is Projectile)
     {
         var p = entity as Projectile;
         Projectiles.TryRemove(new Tuple <int, byte>(p.ProjectileOwner.Self.Id, p.ProjectileId), out p);
     }
     else if (entity is StaticObject)
     {
         StaticObject dummy;
         StaticObjects.TryRemove(entity.Id, out dummy);
         if (entity is Decoy)
         {
             PlayersCollision.Remove(entity);
         }
         else
         {
             EnemiesCollision.Remove(entity);
         }
     }
     else if (entity is ItemEntity)
     {
         ItemEntity dummy;
         EnemiesCollision.Remove(entity);
         ItemEntities.TryRemove(entity.Id, out dummy);
     }
     entity.Dispose();
     entity = null;
 }
Example #10
0
        public IActionResult Add(ItemModel item)
        {
            var entity = new ItemEntities
            {
                Id          = 1,
                Name        = item.Name,
                Description = item.Description,
                IsVisible   = item.IsVisible,
            };

            _dbContext.Items.Add(entity);
            _dbContext.SaveChanges();

            //return View("AddConfirmation", viewModel);
            return(RedirectToAction("AddConfirmation", new { itemId = 1 }));
        }
Example #11
0
        public AddNewItemResponse Post(ItemModel item)
        {
            var entity = new ItemEntities
            {
                Name        = item.Name,
                Description = item.Description,
                IsVisible   = item.IsVisible,
            };

            _dbContext.Items.Add(entity);
            _dbContext.SaveChanges();

            var response = new AddNewItemResponse()
            {
                success   = true,
                message   = "nice! it works!",
                addedItem = item
            };


            return(response);
        }
Example #12
0
        protected void FromWorldMap(Stream dat)
        {
            log.InfoFormat("Loading map for world {0}({1})...", Id, Name);

            Map        = new Wmap(Manager.GameData);
            entityInc  = 0;
            entityInc += Map.Load(dat, 0);

            int w = Map.Width, h = Map.Height;

            EnemiesCollision = new CollisionMap <Entity>(0, w, h);
            PlayersCollision = new CollisionMap <Entity>(1, w, h);

            Projectiles.Clear();
            StaticObjects.Clear();
            Enemies.Clear();
            Players.Clear();
            ItemEntities.Clear();
            foreach (Entity i in Map.InstantiateEntities(Manager))
            {
                EnterWorld(i);
            }
        }
Example #13
0
 private void Awake()
 {
     ItemEntities.Init();
 }
Example #14
0
 void Awake()
 {
     ItemEntities.Init();
     editItem = ItemEntities.items.Values.First();
 }