コード例 #1
0
        protected void handleCollisions(GalaxyRegistrationManager rm, ProjectileManager pm)
        {
            ICollidable hitObj;
            var         keysToRemove = new List <int>();

            foreach (var kvp in _collisionsToCheck)
            {
                hitObj = kvp.Value.hitObject;
                int numOnline = 0;

                try
                {
                    //This line for some reason causes null reference exceptions, although none of the variables are null
                    numOnline = _galaxyManager.GetArea(hitObj.CurrentAreaId).NumOnlinePlayers;
                }
                catch (Exception e)
                {
                    ConsoleManager.WriteLine("Mysterious null error in CollisionManager.HandleCollisions.", ConsoleMessageType.Warning);
                    continue;
                }

                if (kvp.Value.isExpired && (TimeKeeper.MsSinceInitialization - kvp.Value.reportTime) >= 3000)
                {    //If it has been handled and the grace period for further reports has ended
                    keysToRemove.Add(kvp.Value.projectileID);
                }
                else if (kvp.Value.isExpired == false &&
                         (TimeKeeper.MsSinceInitialization - kvp.Value.reportTime) >= 200)
                //Only one collision reported
                {
                    //ConsoleManager.WriteToFreeLine("Single Reported");
                    //Program.numSingleCols++;
                    float probability = (1f / numOnline) * 100; //probability that the collision is valid

                    if (r.Next(0, 100) <= probability)
                    {
                        if (_projectileManager.idToProjectile.ContainsKey(kvp.Value.projectileID))
                        {
                            DamageObject(hitObj, _projectileManager.idToProjectile[kvp.Value.projectileID].FiringObject, kvp.Value.projectileType, kvp.Value.pctCharge, kvp.Value.WeaponSlot, kvp.Value.projectileID);//Collision considered valid
                        }
                        else
                        {
                            ConsoleManager.WriteLine("Error: projectileID not found for projectile collision. Skipping damage...", ConsoleMessageType.Error);
                        }
                    }

                    kvp.Value.isExpired = true;
                }
            }


#if DEBUG
            //TODO: Remove this before release
            for (int i = 0; i < keysToRemove.Count - 1; i++)
            {
                for (int j = i + 1; j < keysToRemove.Count; j++)
                {
                    if (keysToRemove[i] == keysToRemove[j])
                    {
                        ConsoleManager.WriteLine("SAME KEY ADDED TWICE1!!!!");
                        throw new Exception("SAME KEY ADDED TWICE1!!!!");
                    }
                }
            }
#endif
            try
            {
                for (int i = 0; i < keysToRemove.Count; i++)
                {
                    CollisionObject tempCol;
                    //Program.numReports -= _collisionsToCheck[keysToRemove[i]].numReported;
                    recycleCollisionObject(_collisionsToCheck[keysToRemove[i]]);
                    _collisionsToCheck.TryRemove(keysToRemove[i], out tempCol);
                }
            }
            catch
            {
                Console.WriteLine("bsdfjlehliau");
            }
        }
コード例 #2
0
 public void Update(GalaxyRegistrationManager rm, ProjectileManager pm)
 {
     handleCollisions(rm, pm);
 }
コード例 #3
0
ファイル: WarpManager.cs プロジェクト: bsed/Freecon-Galactic
 /// <summary>
 /// This is gross, I know, just go with it.
 /// </summary>
 /// <param name="rm"></param>
 public void SetRegistrationManager(GalaxyRegistrationManager rm)
 {
     _registrationManager = rm;
 }