Esempio n. 1
0
        private static void EnterWorld(object source, System.Timers.ElapsedEventArgs e)
        {
            timer.Enabled = false;
            GlobalVars.log.InfoFormat("enterworld function in bot man");
            var request = new OperationRequest {
                OperationCode = (byte)OperationCode.EnterWorld, Parameters = new Dictionary <byte, object>()
            };

            request.Parameters.Add((byte)ParameterCode.WorldName, world.Name);
            request.Parameters.Add((byte)ParameterCode.Username, "botmn");
            request.Parameters.Add((byte)ParameterCode.Position, new Vector(500, 500));
            request.Parameters.Add((byte)ParameterCode.ViewDistanceEnter, new Vector(400f, 400f));
            request.Parameters.Add((byte)ParameterCode.ViewDistanceExit, new Vector(800f, 800f));

            SendParameters sp = MmoActorOperationHandler.GetDefaultSP();

            //     sp.Unreliable = false;
            ((MmoInitialOperationHandler)serverPeer.CurrentOperationHandler).OperationEnterWorld(
                serverPeer, request, sp, true);

            timer          = new System.Timers.Timer();
            timer.Elapsed += new System.Timers.ElapsedEventHandler(Update);
            timer.Interval = 50; // 50ms
            timer.Enabled  = true;
            watch          = new Stopwatch();
            watch.Start();
        }
Esempio n. 2
0
        private static void SpawnMobHelper(Mob newMob)
        {
            mobTable.Add(newMob.mobItem.Id, newMob);
            newMob.mobItem.World.ItemCache.AddItem(newMob.mobItem);
            newMob.mobItem.UpdateRegionSimple();

            GlobalVars.log.InfoFormat("adding bot to botman");
            // send event
            var eventInstance = new BotSpawn
            {
                ItemId   = newMob.mobItem.Id,
                Position = newMob.mobItem.Position,
                Rotation = newMob.mobItem.Rotation,
            };

            SendParameters sp = MmoActorOperationHandler.GetDefaultSP();
            //  sp.Unreliable = false;
            var eventData = new EventData((byte)EventCode.BotSpawn, eventInstance);
            var message   = new ItemEventMessage(newMob.mobItem, eventData, sp);

            newMob.mobItem.EventChannel.Publish(message);
            ((MmoActorOperationHandler)serverPeer.CurrentOperationHandler).AddItem(newMob.mobItem);
            //todo add bot to radar, just check that the world is the right one
            // ((World)this.World).Radar.AddItem(item, operation.Position);
        }
Esempio n. 3
0
        public static void MobFireBullet(Item mob)
        {
            GlobalVars.log.InfoFormat("mob" + mob.Id + "firing");
            var request = new OperationRequest {
                OperationCode = (byte)OperationCode.FireBullet, Parameters = new Dictionary <byte, object>()
            };

            request.Parameters.Add((byte)ParameterCode.ItemId, mob.Id);
            request.Parameters.Add((byte)ParameterCode.Rotation, mob.Rotation);
            request.Parameters.Add((byte)ParameterCode.Position, mob.Position);
            SendParameters sp = MmoActorOperationHandler.GetDefaultSP();

            ((MmoActorOperationHandler)serverPeer.CurrentOperationHandler).OperationFireBullet(serverPeer, request, sp);
        }
Esempio n. 4
0
File: Mob.cs Progetto: geosohal/Mmo
        public void Regenerate(float elapsedSec)
        {
            if (hp >= GlobalVars.MotherHP)
            {
                return;
            }
            hpAccumulated += elapsedSec * HPregenPerSec;
            if (hpAccumulated > hpRegainAmount)
            {
                int hpToAdd = (int)hpAccumulated;
                hp           += hpToAdd;
                hpAccumulated = hpAccumulated - (float)Math.Floor(hpAccumulated);

                var eventInstance1 = new HpEvent
                {
                    ItemId   = this.mobItem.Id,
                    HpChange = -hpToAdd,
                };
                var eventData1 = new EventData((byte)EventCode.HpEvent, eventInstance1);
                var message1   = new ItemEventMessage(target.Avatar, eventData1, MmoActorOperationHandler.GetDefaultSP());
                mobItem.EventChannel.Publish(message1);
            }
        }
Esempio n. 5
0
        private static void Update(object source, System.Timers.ElapsedEventArgs e)
        {
            watch.Stop();   // sets elapsed time to time since watch.Start() was called
            TimeSpan ts             = watch.Elapsed;
            float    msElapsed      = (float)ts.Milliseconds;
            float    elapsedSeconds = msElapsed / 1000f;

            if (timeTillMotherSpawn > 0)
            {
                timeTillMotherSpawn -= elapsedSeconds;
            }

            if (motherMobs.Count < GlobalVars.MaxMotherBots && timeTillMotherSpawn <= 0)
            {
                Vector pos = GetRandomCentralPosition();
                AddMotherBotHelper(pos, world);
                timeTillMotherSpawn = GlobalVars.SecForMotherToRespawn;
            }


            foreach (MobMother mm in motherMobs)
            {
                mm.Regenerate(elapsedSeconds);
                if (mm.isDead && mm.childMobs.Count == 0)
                {
                    motherMobs.Remove(mm);
                    break;
                }
                mm.timeTillNextSpawn -= elapsedSeconds;
                // if its time to spawn next mob
                if (!mm.isDead && mm.timeTillNextSpawn <= 0 && mm.childMobs.Count < GlobalVars.MaxSwarmPerMother)
                {
                    // spawn next mob
                    Vector displacement = MathHelper.GetRandomVector(GlobalVars.SpawnDistFromMother);
                    Vector mobPos       = mm.mobItem.Position + displacement;
                    AddMobToMotherrHelper(mobPos, mm, world);

                    float t = (float)mm.childMobs.Count / (float)GlobalVars.MaxSwarmPerMother;
                    mm.timeTillNextSpawn = MathHelper.Lerp(GlobalVars.SecMinForSwarmSpawn,
                                                           GlobalVars.SecMaxForSwarmSpawn, t);
                }

                mm.CheckCollisions(elapsedSeconds, Sp, serverPeer);

                foreach (Mob mob in mm.childMobs)
                {
                    // update positions of all children (also sends itemmoved event)
                    mob.UpdatePosition(elapsedSeconds, MmoActorOperationHandler.GetDefaultSP());
                    mob.CheckCollisions(elapsedSeconds, Sp, serverPeer);
                    mob.UpdateState(elapsedSeconds);
                }

                RemoveDeadMobsFromMother(mm);
            }

            // Asteroid spawner update:
            //if (timeSinceLastMake > timeToMake)
            //{
            //    int numAsteroids = asteroids.Length;
            //    int randIndex = Random.Range(0, numAsteroids - 1);

            //    Transform asteroidTransform = this.transform;
            //    Vector3 astPos =
            //        new Vector3(transform.position.x + Random.RandomRange(-xradius, xradius), transform.position.y, transform.position.z);
            //    GameObject newAsteroid = Instantiate(asteroids[randIndex], astPos, Quaternion.identity);
            //    float xVel = speedX + Random.RandomRange(-speedVarianceX, speedVarianceX);
            //    float yVel = speedY + Random.RandomRange(-speedVarianceY, speedVarianceY);
            //    Vector3 asteroidVel = new Vector3(xVel, 0, yVel);
            //    newAsteroid.GetComponent<Rigidbody>().velocity = asteroidVel;
            //    newAsteroid.GetComponent<Rigidbody>().AddTorque(
            //        Random.RandomRange(-torqueRange, torqueRange), Random.RandomRange(-torqueRange, torqueRange), Random.RandomRange(-torqueRange, torqueRange));
            //    timeSinceLastMake = 0;
            //    rb.asteroids.Add(newAsteroid.GetComponent<Asteroid>());
            //}

            watch = Stopwatch.StartNew();
        }