Example #1
0
        public static FieldObjectEntity createBlank(FieldObjectID id)
        {
            var exist = Rank.None;

            //debugLogFirldObjectID(id);

            foreach (Rank rank in Enum.GetValues(typeof(Rank)))
            {
                //debugLogRank(rank);
                if (rank == Rank.None)
                {
                    continue;
                }

                if (!base_resources.ContainsKey(rank))
                {
                    throw new Exception("rank Not found in base_resources" + Enum.GetName(typeof(Rank), rank));
                }

                if (base_resources[rank].ContainsKey(id))
                {
                    exist = rank;
                }
            }

            if (exist == Rank.None)
            {
                throw new Exception("Key not found in FieldObjectEntity base resouces.");
            }

            var resource = base_resources[exist][id];

            var entity = new FieldObjectEntity {
                id   = entity_id,
                type = resource.type,
                size = resource.size,
                //prefab_path = resource.prefab_path,
                prefab_id      = resource.prefab_id,
                inventory_size = resource.inventory_size,
            };

            var go_base = prefabs[entity.prefab_id];

            entity.game_object = Object.Instantiate(go_base);
            var foc = entity.game_object.GetComponent <FieldObjectController>();

            if (foc != null)
            {
                foc.id = entity_id;
            }
            entity.game_object.SetActive(false);

            entity_id += 1;
            return(entity);
        }
Example #2
0
        public static FieldObjectEntity setupInventory(FieldObjectEntity entity)
        {
            //Debug.Log("entity.id: " + entity.id);
            //Debug.Log("entity.inventory_size: " + entity.inventory_size);

            FieldObjectService.setupInventory(entity.id, entity.inventory_size);
            if (entity.inventory_size < 1)
            {
                return(entity);
            }

            var equip = EquipFactory.createRandomEntity();

            FieldObjectService.setInventory(entity.id, equip);
            return(entity);
        }
Example #3
0
/*
 *      public static void debugLogRank(Rank rank) {
 *          switch(rank) {
 *              case Rank.None: Debug.Log("Rank.None"); break;
 *              case Rank.D: Debug.Log("Rank.D"); break;
 *              case Rank.C: Debug.Log("Rank.C"); break;
 *              case Rank.B: Debug.Log("Rank.B"); break;
 *              case Rank.A: Debug.Log("Rank.A"); break;
 *              case Rank.S: Debug.Log("Rank.S"); break;
 *          }
 *      }
 */
/*
 *      public static void debugLogFirldObjectID(FieldObjectID id) {
 *          switch(id) {
 *              case FieldObjectID.None: Debug.Log("FieldObjectID.None"); break;
 *              case FieldObjectID.TreasureBox: Debug.Log("FieldObjectID.TreasureBox"); break;
 *              case FieldObjectID.Torch: Debug.Log("FieldObjectID.Torch"); break;
 *          }
 *      }
 */

        public static FieldObjectEntity setupRandomPosition(FieldObjectEntity entity)
        {
            var pos = EffectiveFloorService.rand(entity.size);

            if (pos == null)
            {
                return(null);
            }

            entity.position = pos.position;
            entity.rotation = pos.rotation;
            entity.game_object.transform.position = pos.position;
            entity.game_object.transform.Rotate(pos.rotation);
            entity.game_object.SetActive(true);
            return(entity);
        }
        public static FieldObjectEntity createEntity(FieldObjectID id)
        {
            //FieldObjectEntity entity = (FieldObjectEntity)ObjectPoolService.takeOut(Type.Props, id);
            //FieldObjectEntity entity = FieldObjectEntityFactory.createBlank(id);

            /*
             * FieldObjectEntity entity = (FieldObjectEntity)ObjectPoolService.takeOut(Type.Props, id);
             * if (entity == null) { entity = FieldObjectEntityFactory.createBlank(id); }
             */
            FieldObjectEntity entity = FieldObjectEntityFactory.createBlank(id);

            FieldObjectEntityFactory.setupInventory(entity);
            FieldObjectEntityFactory.setupRandomPosition(entity);

/*
 *          if (r == null) {
 *              ObjectPoolService.ret(Type.Props, entity.type, entity);
 *          }
 */
            entity_list.Add(entity.id, entity);
            return(entity);
        }
        public static void OnCollisionEnter(int entity_id, GameObject current)
        {
            //Debug.Log("OnCollisionEnter:111 : entity_id : " + entity_id);

/*
 *          if (!inventory_list.ContainsKey(entity_id)) {
 *              Debug.Log("inventory_list.Count: " + inventory_list.Count);
 *              //throw new KeyNotFoundException("Key not found: " + entity_id);
 *              return;
 *          }
 */
            ItemEntity item;

            try {
                item = getInventory(entity_id);
            } catch (KeyNotFoundException e) {
                //Debug.Log("KeyNotFoundException: " + e.Message);
                return;
            }

            //debugLogItemID(item.type);

            //item.game_object.transform.SetParent(current.transform);
            item.game_object.transform.position += current.transform.position + new Vector3(0, 0.5f, 0);
            //item.game_object.transform.rotation = current.transform.rotation;
            //Debug.Log(item.game_object.transform.position);

/*
 *          BoxCollider b_col = item.game_object.GetComponentInChildren<BoxCollider>();
 *          b_col.isTrigger = true;
 */
            item.game_object.SetActive(true);
            Rigidbody rb = item.game_object.GetComponentInChildren <Rigidbody>();
            //Vector3 jump_force = current.transform.rotation.eulerAngles * open_inventory_force;

            FieldObjectEntity entity = entity_list[entity_id];

            Vector3 jump_force = getItemJumpForce(Mathf.RoundToInt(entity.rotation.y)) * open_inventory_force;
            //Debug.Log("FieldObject::OnCollisionEnter() : entity.rotation : " + entity.rotation.ToString());
            //Debug.Log("FieldObject::OnCollisionEnter() : jump_force : " + jump_force.ToString());

            var original_scale = item.game_object.transform.localScale[0];
            var local_scale    = 0.1f;
            var tmp_scale      = original_scale * local_scale;

            item.game_object.transform.localScale = new Vector3(tmp_scale, tmp_scale, tmp_scale);

            //Debug.Log("FieldObject::OnCollisionEnter() : item.game_object.name : " + item.game_object.name);
            //Debug.Log("FieldObject::OnCollisionEnter() : original_scale : " + original_scale.ToString());

            Observable.Interval(TimeSpan.FromMilliseconds(50)).Take(3).Subscribe(x => {
                local_scale += 0.3f;
                tmp_scale    = original_scale * local_scale;
                item.game_object.transform.localScale = new Vector3(tmp_scale, tmp_scale, tmp_scale);
            });

/*
 *          Observable.Interval(TimeSpan.FromMilliseconds(50)).Take(9).Subscribe(x => {
 *              local_scale += 0.1f;
 *              tmp_scale = original_scale * local_scale;
 *              item.game_object.transform.localScale = new Vector3(tmp_scale, tmp_scale, tmp_scale);
 *          });
 */
            if (rb != null)
            {
                //Debug.Log("rb.AddRelativeForce");
                //rb.AddRelativeForce(new Vector3(0f, rb.mass * open_inventory_force, rb.mass * open_inventory_force), ForceMode.Impulse);
                //rb.AddRelativeForce(jump_force, ForceMode.Impulse);
                rb.AddForce(jump_force, ForceMode.Impulse);
            }
        }
Example #6
0
        public static void init(List <GameObject> foPrefabs)
        {
            prefabs = foPrefabs;

            var tresure_box = new FieldObjectEntity {
                type = FieldObjectID.TreasureBox,
                size = 1,
                //prefab_path = "Props/Chest",
                prefab_id      = 0,
                inventory_size = 1
            };

            var torch = new FieldObjectEntity {
                type = FieldObjectID.Torch,
                size = 1,
                //prefab_path = "Props/Torch",
                prefab_id      = 1,
                inventory_size = 0,
            };

            var candle = new FieldObjectEntity {
                type = FieldObjectID.Candle,
                size = 1,
                //prefab_path = "Props/Candle",
                prefab_id      = 2,
                inventory_size = 0,
            };

            var small_keg = new FieldObjectEntity {
                type = FieldObjectID.SmallKeg,
                size = 1,
                //prefab_path = "Props/Small Keg",
                prefab_id      = 3,
                inventory_size = 0,
            };

            var large_keg = new FieldObjectEntity {
                type = FieldObjectID.LargeKeg,
                size = 1,
                //prefab_path = "Props/Large Keg",
                prefab_id      = 4,
                inventory_size = 0,
            };

            var barrel = new FieldObjectEntity {
                type = FieldObjectID.Barrel,
                size = 1,
                //prefab_path = "Props/Barrel",
                prefab_id      = 5,
                inventory_size = 0,
            };

            base_resources = new Dictionary <Rank, Dictionary <FieldObjectID, FieldObjectEntity> > {
                { Rank.D, new Dictionary <FieldObjectID, FieldObjectEntity> {
                      { FieldObjectID.SmallKeg, small_keg },
                      { FieldObjectID.LargeKeg, large_keg },
                      { FieldObjectID.Barrel, barrel },
                      { FieldObjectID.Torch, torch },
                      { FieldObjectID.Candle, candle },
                  } },

                { Rank.C, new Dictionary <FieldObjectID, FieldObjectEntity> {
                      { FieldObjectID.SmallKeg, small_keg },
                      { FieldObjectID.Barrel, barrel },
                      { FieldObjectID.Torch, torch },
                      { FieldObjectID.Candle, candle },
                  } },

                { Rank.B, new Dictionary <FieldObjectID, FieldObjectEntity> {
                      { FieldObjectID.SmallKeg, small_keg },
                      { FieldObjectID.Barrel, barrel },
                      { FieldObjectID.Candle, candle },
                  } },

                { Rank.A, new Dictionary <FieldObjectID, FieldObjectEntity> {
                      { FieldObjectID.SmallKeg, small_keg },
                      { FieldObjectID.Barrel, barrel },
                  } },

                { Rank.S, new Dictionary <FieldObjectID, FieldObjectEntity> {
                      { FieldObjectID.SmallKeg, small_keg },
                      { FieldObjectID.Barrel, barrel },
                  } },

                { Rank.All, new Dictionary <FieldObjectID, FieldObjectEntity> {
                      { FieldObjectID.TreasureBox, tresure_box },
                  } },
            };
        }