Beispiel #1
0
        void Start()
        {
            Application.targetFrameRate = 60;

            if (ClearProgress)
            {
                ProgressManager.DeleteProgress();
            }

            BaseObjectFactory.SetVariants();
            PlayerModel = new Player();
            PlayerModel.Init(this);
            ProgressManager.LoadProgress(this);

            Player.Init(this);
            IapManager.Init(this);

            SpawnZonesAgragator.Init(this);
            Fauna.Init(this);

            StartCoroutine(AutoSave());

            Pathfinder.Scan();

#if FACEBOOK
            FbManager.Init();
#endif
#if UNITY_IOS
            GameCenterManager.Authenticate();
#endif
#if UNITY_ANDROID
            GooglePlayServicesController.Init();
#endif
        }
Beispiel #2
0
 public void AddStartLoot()
 {
     foreach (var item in LootChests)
     {
         AddPlacedItem(item.gameObject, BaseObjectFactory.GetItem(typeof(Chest)));
     }
 }
Beispiel #3
0
        void OnTriggerEnter(Collider other)
        {
            if (!_isShoot)
            {
                return;
            }

            if (other.tag == "Player")
            {
                return;
            }

            RigidBody.velocity        = Vector3.zero;
            RigidBody.angularVelocity = Vector3.zero;
            RigidBody.useGravity      = false;
            var animalLink = other.gameObject.GetComponent <AnimalColliderLink>();

            if (animalLink != null)
            {
                var item = BaseObjectFactory.GetItem(typeof(Arrow));
                animalLink.SetDamage(item.Damage, transform.position);
            }
            else
            {
                Vector3 forward = transform.TransformDirection(Vector3.forward) * SphereColliderRadius;
                Debug.DrawRay(transform.position, forward, Color.green);

                var        location       = transform.position;
                Collider[] objectsInRange = Physics.OverlapSphere(location, SphereColliderRadius);
                foreach (Collider col in objectsInRange)
                {
                    var enemy = col.GetComponent <AnimalColliderLink>();
                    if (enemy != null)
                    {
                        var item = BaseObjectFactory.GetItem(typeof(Arrow));
                        enemy.SetDamage(item.Damage, transform.position);
                        break;
                    }
                    //if (enemy != null)
                    //{
                    //    float proximity = (location - enemy.transform.position).magnitude;
                    //    float effect = 1 - (proximity / SphereColliderRadius);
                    //}
                    //var player = col.GetComponent<PlayerController>();
                    //if(player != null)
                    //{
                    //    float proximity = (location - col.transform.position).magnitude;
                    //    float effect = 1 - (proximity / SphereColliderRadius);
                    //    player.MakeDamage(100 * effect);
                    //}
                }
            }

            StopAllCoroutines();
            Destroy(gameObject);
        }
Beispiel #4
0
        private IEnumerator CheckShoot()
        {
            yield return(new WaitForSeconds(0.3f));

            var        ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
            RaycastHit hit;
            int        waterLayerMask = 1 << 4; //берем слой воды

            waterLayerMask = ~waterLayerMask;   //инвентируем, теперь в переменной все слои крое воды
            if (Physics.Raycast(ray, out hit, 150f, waterLayerMask))
            {
                var distance = Vector3.Distance(transform.position, hit.collider.transform.position);
                var precent  = 100;
                if (distance > 100)
                {
                    precent = 60;
                }
                else if (distance > 70)
                {
                    precent = 70;
                }
                else if (distance > 50)
                {
                    precent = 80;
                }

                var rand = Random.Range(0, 100);
                if (rand < precent)
                {
                    var enemy = hit.collider.gameObject.GetComponent <AnimalColliderLink>();
                    if (enemy != null)
                    {
                        var item = BaseObjectFactory.GetItem(typeof(CrossbowArrow));
                        enemy.SetDamage(item.Damage);
                    }
                }
            }

            var amountArrow = _gameManager.PlayerModel.Inventory.GetAmount(typeof(CrossbowArrow));

            if (amountArrow > 0)
            {
                Reload();
            }
            else
            {
                CurrentState = CrossbowState.Ready;
            }
        }
Beispiel #5
0
        public void Init(GameManager gameManager, IapGoodItem iapItem, ShopView shop)
        {
            base.Init(gameManager);

            IapItem = iapItem;
            _item   = BaseObjectFactory.GetItem(IapItem.RewardItemName);
            _shop   = shop;

            NameLabel.text        = Localization.Get(IapItem.LocalizedTitle);
            IconSprite.spriteName = _item.IconName;
            PriceLabel.text       = IapItem.Price.ToString();
            AmountLabel.text      = "x" + IapItem.RewardAmount;

            UIEventListener.Get(BuyButton).onClick += OnBuyClick;
        }
Beispiel #6
0
        public void Init(string id, int amount)
        {
            if (id == "gold")
            {
                Icon.spriteName       = "gold_icon";
                DescriptionLabel.text = Localization.Get("gold_name");
            }
            else
            {
                var item = BaseObjectFactory.GetItem(id);
                Icon.spriteName       = item.IconName;
                DescriptionLabel.text = Localization.Get(item.LocalizationName);
            }

            AmountLabel.text = amount.ToString();
        }
Beispiel #7
0
        private void OnAddItemToInventory(object o)
        {
            var item = o as HolderObject;

            if (item != null && item.Item is Ammo)
            {
                var weaponType = (item.Item as Ammo).WeaponType;
                if (weaponType != null)
                {
                    var weapon    = BaseObjectFactory.GetItem(weaponType);
                    var curWeapon = false;
                    if (_currentWeapon != null)
                    {
                        curWeapon = _currentWeapon.Item.GetType() == weapon.GetType();
                    }
                    (weapon as Weapon).SetAmmo(_gameManager, curWeapon);
                }
            }
        }
Beispiel #8
0
        private void ConfigureIoC(params Type[] expectedTypes)
        {
            objectFactory = mocks.PartialMock <BaseObjectFactory>();

            var typesList = new List <Type>(expectedTypes)
            {
                typeof(NullPersistenceContext),
                //by default
                typeof(TestExecutionContext)
            };

            objectFactory.Expect("AddToContext").Repeat.Times(typesList.Count)
            .Callback((Lemming l) => typesList.Remove(l.ConcreteType));

            objectFactory.Expect("FindObjectByName").IgnoreArguments().Repeat.Any().Return(null);
            objectFactory.Expect("FindObjectByType").IgnoreArguments().Repeat.Any().Return(null);
            objectFactory.Expect(x => x.GetObject(default(Type))).IgnoreArguments().Repeat.Any().Return(null);
            iocContainer.Expect(x => x.GetObjectFactory()).Return(objectFactory).Repeat.Any();

            mocks.ReplayAll();
        }
Beispiel #9
0
        public void Init(GameManager gameManager, CraftCategory category, Type itemType, string amount)
        {
            base.Init(gameManager);

            _itemType = itemType;
            ItemModel = BaseObjectFactory.GetItem(itemType);
            CanCraft  = GameManager.PlayerModel.Inventory.CheckItems(ItemModel.CraftRecipe);
            Category  = category;

            Icon.spriteName  = ItemModel.IconName;
            AmountLabel.text = amount;
            if (Name != null)
            {
                Name.text = Localization.Get(ItemModel.LocalizationName);
            }
            if (CanCraftBackground != null)
            {
                CanCraftBackground.enabled = CanCraft;
            }

            UIEventListener.Get(gameObject).onClick += OnItemClick;
        }
Beispiel #10
0
        public void PlaceSavedItems(List <GroundItemSaveModel> items)
        {
            foreach (var item in LootChests)
            {
                item.gameObject.SetActive(false);
            }

            foreach (var groundItemSaveModel in items)
            {
                var item = BaseObjectFactory.GetItem(groundItemSaveModel.ItemName);

                string prefabPath = string.Empty;
                if (!groundItemSaveModel.Dropped && item is IPlacement)
                {
                    prefabPath = (item as IPlacement).PrefabPath;
                }
                else
                {
                    prefabPath = item.OnGroundPrefabPath;
                }

                var itemPrefab = Resources.Load <GameObject>(prefabPath);
                var itemGo     = Instantiate(itemPrefab);
                if (groundItemSaveModel.Dropped)
                {
                    itemGo.GetComponent <WorldItem>().SetItem(item.GetType(), groundItemSaveModel.Amount, groundItemSaveModel.Durability);
                }

                itemGo.transform.position = new Vector3(groundItemSaveModel.PosX, groundItemSaveModel.PosY,
                                                        groundItemSaveModel.PosZ);
                itemGo.transform.rotation =
                    Quaternion.Euler(new Vector3(groundItemSaveModel.Pitch, groundItemSaveModel.Roll,
                                                 groundItemSaveModel.Yaw));

                var destroyable = itemGo.GetComponentInChildren <DestroyableObject>();
                if (destroyable != null)
                {
                    destroyable.CurrentHp   = groundItemSaveModel.CurrentHp;
                    destroyable.ItemModel   = item;
                    destroyable.Initialized = true;
                }

                if (groundItemSaveModel.IsActive)
                {
                    var iconverter = itemGo.GetComponent <IConverter>();
                    if (iconverter != null)
                    {
                        iconverter.AutoStart = true;
                    }
                }

                var filledItem = itemGo.GetComponent <IFilled>();
                if (filledItem != null)
                {
                    filledItem.CurrentFilledAmount = groundItemSaveModel.AmountFilled;
                }

                AddPlacedItem(itemGo, item, groundItemSaveModel.Dropped, groundItemSaveModel.Amount);

                var inventoryItem = itemGo.GetComponent <IInventoryThing>();
                if (groundItemSaveModel.InventoryList != null && inventoryItem != null)
                {
                    var inventoryList = new List <InventoryBase>();
                    foreach (var invListModel in groundItemSaveModel.InventoryList.InventoryList)
                    {
                        var currentInventory = new InventoryBase();
                        currentInventory.Init(invListModel.SlotAmount);
                        foreach (var invItemModel in invListModel.Items)
                        {
                            var amount = invItemModel.Amount;
                            if (currentInventory.Slots.Count <= invItemModel.SlotId)
                            {
                                currentInventory.Slots.Add(null);
                            }
                            currentInventory.Slots[invItemModel.SlotId] =
                                HolderObjectFactory.GetItem(invItemModel.ItemName, amount,
                                                            invItemModel.CurrentDurability);
                        }
                        inventoryList.Add(currentInventory);
                    }
                    inventoryItem.SetInventoryList(inventoryList);
                }
            }

            SetActiveConstructionColliders(false);
        }