コード例 #1
0
 public override void Tick()
 {
     base.Tick();
     NextBoing -= TheRegion.Delta;
     if (NextBoing <= 0)
     {
         NextBoing = Utilities.UtilRandom.NextDouble() * 2 + 0.5;
         XMove     = (double)Utilities.UtilRandom.NextDouble() * 2f - 1f;
         YMove     = (double)Utilities.UtilRandom.NextDouble() * 2f - 1f;
         Upward    = Utilities.UtilRandom.Next(100) > 75;
     }
     NextAttack -= TheRegion.Delta;
     if (NextAttack <= 0)
     {
         PlayerEntity player = NearestPlayer(out double distsq);
         if (distsq < 10 * 10)
         {
             Location target = player.GetCenter();
             Location pos    = GetEyePosition();
             Location rel    = (target - pos).Normalize();
             Direction = Utilities.VectorToAngles(rel);
             Items.Items[0].Info.Click(this, Items.Items[0]);
             Items.Items[0].Info.ReleaseClick(this, Items.Items[0]);
         }
         NextAttack = Utilities.UtilRandom.NextDouble() * 2 + 0.5;
     }
 }
コード例 #2
0
ファイル: SlimeEntity.cs プロジェクト: MoTo1496/Voxalia
 public override void Tick()
 {
     if (Math.Abs(XMove) > 0.1 || Math.Abs(YMove) > 0.1)
     {
         CBody.Jump();
     }
     if (ApplyDamage > 0)
     {
         ApplyDamage -= TheRegion.Delta;
     }
     TargetPlayers -= TheRegion.Delta;
     if (TargetPlayers <= 0)
     {
         PlayerEntity player = NearestPlayer(out double dist);
         if (player != null && dist < MaxPathFindDistance * MaxPathFindDistance)
         {
             GoTo(player);
             CBody.Jump();
             ApplyForce((player.GetCenter() - GetCenter()).Normalize() * GetMass());
         }
         else
         {
             GoTo(null);
         }
         TargetPlayers = 1;
     }
     base.Tick();
 }
コード例 #3
0
ファイル: HookItem.cs プロジェクト: Morphan1/Voxalia
 public void ApplyHook(PlayerEntity player, ItemStack item, Location Position, BEPUphysics.Entities.Entity HitEnt)
 {
     RemoveHook(player);
     PhysicsEntity pe;
     double len = (double)(Position - player.GetCenter()).Length();
     Location step = (player.GetCenter() - Position) / len;
     Location forw = Utilities.VectorToAngles(step);
     BEPUutilities.Quaternion quat = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), (double)(forw.Pitch * Utilities.PI180)) *
         Quaternion.CreateFromAxisAngle(new Vector3(0, 0, 1), (double)(forw.Yaw * Utilities.PI180));
     if (HitEnt == null)
     {
         ModelEntity mod = new ModelEntity("cube", player.TheRegion);
         mod.Mass = 0;
         mod.CanSave = false;
         mod.scale = new Location(0.023, 0.05, 0.05);
         mod.mode = ModelCollisionMode.AABB;
         mod.SetPosition(Position);
         mod.SetOrientation(quat);
         player.TheRegion.SpawnEntity(mod);
         pe = mod;
         player.Hooks.Add(new HookInfo() { Joint = null, Hit = pe, IsBar = true });
     }
     else
     {
         pe = (PhysicsEntity)HitEnt.Tag;
     }
     JointDistance jd;
     //jd = new JointDistance(player, pe, 0.01f, len + 0.01f, player.GetCenter(), Position);
     //player.TheRegion.AddJoint(jd);
     //player.Hooks.Add(new HookInfo() { Joint = jd, Hit = pe, IsBar = false });
     PhysicsEntity cent = pe;
     for (double f = 0; f < len - 1f; f += 0.5f)
     {
         Location cpos = Position + step * f;
         ModelEntity ce = new ModelEntity("cube", player.TheRegion);
         ce.Mass = 15;
         ce.CanSave = false;
         ce.scale = new Location(0.023, 0.05, 0.05);
         ce.mode = ModelCollisionMode.AABB;
         ce.SetPosition(cpos + step * 0.5);
         ce.SetOrientation(quat);
         player.TheRegion.SpawnEntity(ce);
         jd = new JointDistance(ce, cent, 0.01f, 0.5f, ce.GetPosition(), (ReferenceEquals(cent, pe) ? Position: cent.GetPosition()));
         CollisionRules.AddRule(player.Body, ce.Body, CollisionRule.NoBroadPhase);
         player.TheRegion.AddJoint(jd);
         player.Hooks.Add(new HookInfo() { Joint = jd, Hit = ce, IsBar = true });
         cent = ce;
     }
     jd = new JointDistance(cent, player, 0.01f, 0.5f, cent.GetPosition(), player.GetCenter());
     player.TheRegion.AddJoint(jd);
     player.Hooks.Add(new HookInfo() { Joint = jd, Hit = player, IsBar = false });
 }