Пример #1
0
        private void ReceiveDamageReport(SmartShell shell, Dictionary <int, float> damageReport)
        {
            const float rewardPerDamage = 0.005f;  // max damage is 100
            const float penaltySelfHit  = -1.5f;

            if (!IsDone())
            {
                foreach (var entry in damageReport)
                {
                    if (entry.Key == this.id)  // we hit ourself
                    {
                        AddReward(entry.Value * rewardPerDamage * penaltySelfHit);
                        // Debug.unityLogger.Log(LOGTAG, "Player " + id.ToString() + " hit themself for " + entry.Value.ToString());
                    }
                    else  // we hit someone else
                    {
                        AddReward(entry.Value * rewardPerDamage);
                        // Debug.unityLogger.Log(LOGTAG, "Player " + id.ToString() + " hit " + entry.Key.ToString() + " for " + entry.Value.ToString());
                    }
                }
            }

            shell.OnExplode -= ReceiveDamageReport;

            // after calculating rewards, check to see if we won the game
            if (damageReport.Count > 0 && !IsDone())
            {
                gameManager.CheckGameWinConditions();
            }
        }
Пример #2
0
        private void FireCannon(float strength)
        {
            if (cannonCoolingDown || IsDone())
            {
                return;
            }

            cannonCoolingDown = true;
            cooldownTimer     = 0f;
            // StartCoroutine(CannonCooldown());
            Rigidbody shell = Instantiate(shellPrefab, shellSpawnPoint.position, shellSpawnPoint.rotation) as Rigidbody;

            shell.velocity = strength * shellSpawnPoint.forward;

            SmartShell smartShell = shell.GetComponent <SmartShell>();

            if (smartShell)
            {
                smartShell.owner      = id;
                smartShell.OnExplode += ReceiveDamageReport;
            }
        }