示例#1
0
文件: GameData.cs 项目: kayorga/3DSP
 public GameData(ContentManager Content, GraphicsDevice device, AudioManager audio, World world)
 {
     player = new Player(world, Content, audio, device);
     mods = new ModCollection();
     npcs = new NPCCollection(world, Content, player, device, audio);
     bullets = new BulletCollection(Content, device);
     missions = new MissionCollection(world, npcs);
     this.world = world;
     this.audio = audio;
 }
示例#2
0
        public override void reward(Player player, ModCollection mods)
        {
            int exp = (int)(40 * (float)level / (float)player.level);
                exp = Math.Min(exp, 75);
                exp = Math.Max(exp, 1);

                if (player.lv != 50)
                {
                    player.getEXP(exp);
                    countXPGained += exp;
                }

            if (startLv < player.level)
            {
                mods.generate(Math.Min(player.level, level));
                rewardLabel = mods.lastMod;
            }
            else rewardLabel = "-";
        }
示例#3
0
        public void update(NPCCollection npcs, Player p, Mission m, bool isMainMission = false)
        {
            if (!active) return;
            if (cooldown == 0)
            {
                Vector3 pos = new Vector3(Constants.MAP_SIZE - 2 * x - 1, 0, Constants.MAP_SIZE - 2 * z - 1);
                Vector3 dir = p.Position - pos;

                dir.Normalize();

                if (isMainMission && kind != Constants.NPC_BOSS)
                    npcs.generate(kind, pos, dir, m.level - 10);
                else npcs.generate(kind, pos, dir, m.level);

                if (rate == Constants.SPAWN_ONCE)
                    active = false;
                else
                    cooldown = new Random().Next((int)(maxCooldown * 0.6f), (int)(maxCooldown * 1.0f));
            }
            else cooldown = Math.Max(cooldown - 1, 0);
        }
示例#4
0
文件: World.cs 项目: kayorga/3DSP
 public void update(NPCCollection npcs, Player p, Mission m, bool isMainMission = false)
 {
     foreach (NPCSpawner spawner in spawners)
         spawner.update(npcs, p, m, isMainMission);
 }
示例#5
0
 public override void reward(Player player, ModCollection modCollection)
 {
     throw new NotImplementedException();
 }
示例#6
0
文件: NPC.cs 项目: kayorga/3DSP
        /// <summary>
        /// assigns NPC attributes and ModelObject and activates the NPC
        /// </summary>
        /// <param name="k">NPC kind/species</param>
        /// <param name="m">ModelObject</param>
        /// <param name="p">starting position</param>
        /// <param name="d">starting direction</param>
        /// <param name="l">level</param>
        /// <param name="pl">Player</param>
        /// <param name="npcs">parent NPCCollection (should always be "this")</param>
        public void setup(byte k, ModelObject m, Vector3 p, Vector3 d, int l, Player pl, NPCCollection npcs, byte elem = Constants.ELM_NIL)
        {
            kind = k;
            model = m;
            position = p;
            direction = d;
            level = l;

            if (kind == Constants.NPC_BOSS)
                level = Math.Min(60, Math.Max(1, level));
            else level = Math.Min(50, Math.Max(1, level));

            playerDistance = (pl.Position - this.Position).Length();

            #region kind specific stats
            switch (kind)
            {
                case Constants.NPC_NONE:
                    speed = 0.03f;
                    maxHealth = (int)(50 * Math.Pow(1.05f, level - 1));
                    XP = 2;
                    maxCooldn = 70;
                    model.Scaling = new Vector3(0.75f, 0.75f, 0.75f);
                    element = Constants.ELM_NIL;
                    strength = (byte)(10 * Math.Pow(1.045f, level - 1));
                    break;
                case Constants.NPC_PLAS:
                    speed = 0.035f;
                    maxHealth = (int)(50 * Math.Pow(1.045f, level - 1));
                    XP = 3;
                    maxCooldn = 80;
                    model.Scaling = new Vector3(0.75f, 0.75f, 0.75f);
                    element = Constants.ELM_PLA;
                    strength = (byte)(10 * Math.Pow(1.05f, level - 1));
                    break;
                case Constants.NPC_HEAT:
                    speed = 0.04f;
                    maxHealth = (int)(50 * Math.Pow(1.04f, level - 1));
                    XP = 3;
                    maxCooldn = 75;
                    model.Scaling = new Vector3(0.5f, 0.5f, 0.5f);
                    element = Constants.ELM_HEA;
                    strength = (byte)(10 * Math.Pow(1.055f, level - 1));
                    break;
                case Constants.NPC_ICE:
                    speed = 0.03f;
                    maxHealth = (int)(50 * Math.Pow(1.055f, level - 1));
                    XP = 3;
                    maxCooldn = 90;
                    model.Scaling = new Vector3(0.75f, 0.75f, 0.75f);
                    element = Constants.ELM_ICE;
                    strength = (byte)(10 * Math.Pow(1.04f, level - 1));
                    break;
                case Constants.NPC_BOSS:
                    speed = 0.02f;
                    maxHealth = (int)(200 * Math.Pow(1.07f, level - 1));
                    XP = 70;
                    maxCooldn = 50;
                    model.Scaling = new Vector3(0.75f, 0.75f, 0.75f);
                    element = elem;
                    strength = (byte)Math.Min((10 * Math.Pow(1.06f, level - 1)), 255);
                    break;
                default:
                    speed = 0.001f;
                    maxHealth = 1;
                    XP = 0;
                    maxCooldn = 1000;
                    break;
            }
            #endregion

            health = maxHealth;
            active = true;
            model.Position = this.position;
            moving = false;
            newTarget = false;
            isHit = false;
            hitTimer = 0;
            isDead = false;
            pathFinder = npcs.PathFinder;
            target = new Vector3(position.X, position.Y, position.Z);
        }
示例#7
0
文件: NPC.cs 项目: kayorga/3DSP
        public bool update(GameTime gameTime, BulletCollection bullets, Camera camera, Player p, Mission m)
        {
            #region npc death
            //die and grant xp
            if (health <= 0 && !isDead)
            {
                int exp = (int)(XP * (float)level / (float)p.level);
                exp = Math.Min(exp,(int) (XP * 1.5f));
                exp = Math.Max(exp, 1);
                if (p.lv == 50) exp = 0;
                else p.getEXP(exp);
                m.update(kind, exp);
                isDead = true;
                isHit = false;
                hitTimer = 0;
                explosion.Position = Position + new Vector3(0, 0.5f, 0);
                explosion.Initialize(camera);
            }

            //Explosion Update if NPC is down
            if (isDead && active)
            {
                hitTimer++;
                explosion.Update(gameTime, camera);
                if (hitTimer > 25)
                {
                    active = false;
                    isDead = false;
                    this.explosion.Clear();
                    dmgNumbers.Clear();
                    return false;
                }
            }
            #endregion

            #region shoot

            //shoot if player is within shooting distance and not on cooldown
            if (playerDistance <= world.shootDistance && cooldown == 0)
            {
                cooldown = maxCooldn;
                Vector3 dir = (p.position - position);
                dir.Normalize();
                bullets.generate(false, position + dir, dir, 1, world.shootDistance * 2, strength, element);
                audio.playShoot(false);
            }

            if (cooldown > 0) cooldown--;
            #endregion

            #region move
            //if (moving)
                //move();
            //else

            if (!moving || !move())
            {
                {
                    pathFinder.setup(new Point((int)Math.Round((-1 * position.X + world.size - 1)), (int)Math.Round((-1 * position.Z + world.size - 1))), p);
                    target = pathFinder.findPath(kind == Constants.NPC_BOSS);
                    newTarget = true;
                    direction = target - position;
                    if (direction.Length() != 0) direction.Normalize();
                    moving = true;
                    //move();
                }
            }

            #endregion

            #region get hit billboard/dmg number
            //Hit Notification
            if (isHit)
            {
                hitTimer++;
                billboardEngine.AddBillboard(this.position + new Vector3(0, 2, 0), Color.Red, 1.5f);
                if (hitTimer == 70)
                {
                    isHit = false;
                    hitTimer = 0;
                }
            }
            #endregion

            //Rotate Model
            double rotationAngle = Math.Acos((Vector3.Dot(direction, -1 * Vector3.UnitX)) / (direction.Length()));
            rotationAngle = (p.Position.Z < this.Position.Z) ? rotationAngle * -1.0f : rotationAngle;
            rotationAngle += (this.kind == Constants.NPC_BOSS) ? Math.PI / 2 : -Math.PI / 2;
            model.Rotation = new Vector3(0, (float)(rotationAngle), 0);

            //Update PlayerDistance
            playerDistance = (p.Position - this.Position).Length();

            if (playerDistance < 4)
            {
                target = position;
                direction = p.Position - this.Position;
            }

            return true;
        }
示例#8
0
文件: NPC.cs 项目: kayorga/3DSP
        public void getHit(Player p)
        {
            if (!isDead)
            {
                int dmg = p.lv;

                health = Math.Max(health - dmg, 0);
            }
        }
示例#9
0
文件: Bullet.cs 项目: kayorga/3DSP
        private bool updateCycle(GameTime gameTime, Camera camera, World world, NPCCollection npcs, Player p, Mission m, int factor, float spd, float dx, float dz)
        {
            position += spd * direction;
            if (type == Constants.TYP_WAV)
            {
                Vector3 cross = Vector3.Cross(direction, Vector3.Up);
                if (mirror)
                    position -= 0.5f * cross * (float)Math.Sin(waveTime.Milliseconds * 200);
                else
                    position += 0.5f * cross * (float)Math.Sin(waveTime.Milliseconds*200);
                //position += 0.5f * Vector3.Up * (float)Math.Cos(waveTime.Milliseconds);
                //position.X += dx / factor;
                //position.Z += dz / factor;
            }

            distance += spd;

            bulletOb.Position = position;

            particleEffect.Update((float)gameTime.ElapsedGameTime.TotalSeconds, camera.ViewMatrix, position, direction);

            xTile = (byte)Math.Round(-1 * (position.X) + (Constants.MAP_SIZE - 1));
            zTile = (byte)Math.Round(-1 * (position.Z) + (Constants.MAP_SIZE - 1));

            if (collision(world) || collision(npcs, m) || collision(p, m) || distance > maxDist)
            {
                active = false;
                particleEffect.Clear();
                return false;
            }
            return true;
        }
示例#10
0
文件: Bullet.cs 项目: kayorga/3DSP
 //bullet - player collision
 private bool collision(Player p, Mission m)
 {
     if (!fromPlayer && xTile == p.xTile && zTile == p.zTile)
     {
         p.getHit(this, m);
         return true;
     }
     return false;
 }
示例#11
0
文件: Bullet.cs 项目: kayorga/3DSP
        public void update(GameTime gameTime, Camera camera, World world, NPCCollection npcs, Player p, Mission m)
        {
            if (!active) return;

            waveTime += gameTime.ElapsedGameTime;
            float dx = (float)Math.Sin(waveTime.Milliseconds);
            float dz = (float)Math.Cos(waveTime.Milliseconds);

            int factor = (int) Math.Ceiling(speed);

            float remainingSpeed = speed;
            float spd = speed / (float)factor;

            for (int i = 0; i < factor; i++)
            {
                spd = Math.Min(spd, remainingSpeed);
                bool u = updateCycle(gameTime, camera, world, npcs, p, m, factor, spd, dx, dz);
                remainingSpeed -= spd;
                if (!u || remainingSpeed == 0) break;
            }

            return;
        }
示例#12
0
文件: Mission.cs 项目: kayorga/3DSP
 public abstract void reward(Player player, ModCollection modCollection);