mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
Move Hunt/Kill to Instructions class.
This commit is contained in:
parent
3a0c852ab6
commit
036e758e38
@ -14,7 +14,7 @@
|
|||||||
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||||
or implied. See the Licenses for the specific language governing
|
or implied. See the Licenses for the specific language governing
|
||||||
permissions and limitations under the Licenses.
|
permissions and limitations under the Licenses.
|
||||||
*/
|
*/
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -22,14 +22,14 @@ using System.IO;
|
|||||||
namespace MCGalaxy.Bots {
|
namespace MCGalaxy.Bots {
|
||||||
public static class Instructions {
|
public static class Instructions {
|
||||||
|
|
||||||
public static Dictionary<string, Func<PlayerBot, bool>> Defined =
|
public static Dictionary<string, Func<PlayerBot, bool>> Defined =
|
||||||
new Dictionary<string, Func<PlayerBot, bool>>{
|
new Dictionary<string, Func<PlayerBot, bool>>{
|
||||||
{ "walk", DoWalk }, { "teleport", DoTeleport }, { "wait", DoWait },
|
{ "walk", DoWalk }, { "teleport", DoTeleport }, { "wait", DoWait },
|
||||||
{ "nod", DoNod }, { "spin", DoSpin }, { "speed", DoSpeed },
|
{ "nod", DoNod }, { "spin", DoSpin }, { "speed", DoSpeed },
|
||||||
{ "jump", DoJump }, { "reset", DoReset }, { "remove", DoRemove },
|
{ "jump", DoJump }, { "reset", DoReset }, { "remove", DoRemove },
|
||||||
{ "linkscript", DoLinkscript },
|
{ "linkscript", DoLinkscript },
|
||||||
};
|
};
|
||||||
|
|
||||||
static bool DoWalk(PlayerBot bot) {
|
static bool DoWalk(PlayerBot bot) {
|
||||||
bot.foundPos[0] = bot.Waypoints[bot.cur].x;
|
bot.foundPos[0] = bot.Waypoints[bot.cur].x;
|
||||||
bot.foundPos[1] = bot.Waypoints[bot.cur].y;
|
bot.foundPos[1] = bot.Waypoints[bot.cur].y;
|
||||||
@ -135,9 +135,9 @@ namespace MCGalaxy.Bots {
|
|||||||
bot.NextInstruction();
|
bot.NextInstruction();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool DoReset(PlayerBot bot) {
|
static bool DoReset(PlayerBot bot) {
|
||||||
bot.cur = 0;
|
bot.cur = 0;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,5 +154,42 @@ namespace MCGalaxy.Bots {
|
|||||||
}
|
}
|
||||||
bot.NextInstruction(); return true;
|
bot.NextInstruction(); return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
internal static void DoKill(PlayerBot bot) {
|
||||||
|
ushort x = (ushort)Math.Round((decimal)bot.pos[0] / 32);
|
||||||
|
ushort y = (ushort)((bot.pos[1] - 33) / 32);
|
||||||
|
ushort z = (ushort)Math.Round((decimal)bot.pos[2] / 32);
|
||||||
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
|
|
||||||
|
foreach (Player p in players) {
|
||||||
|
if ((ushort)(p.pos[0] / 32) == x
|
||||||
|
&& Math.Abs((ushort)(p.pos[1] / 32) - y) < 2
|
||||||
|
&& (ushort)(p.pos[2] / 32) == z) {
|
||||||
|
p.HandleDeath(Block.Zero);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal static void DoHunt(PlayerBot bot) {
|
||||||
|
int dist = 75 * 32;
|
||||||
|
Player[] players = PlayerInfo.Online.Items;
|
||||||
|
foreach (Player p in players) {
|
||||||
|
if (p.level != bot.level || p.invincible) continue;
|
||||||
|
int curDist = Math.Abs(p.pos[0] - bot.pos[0]) + Math.Abs(p.pos[1] - bot.pos[1]) + Math.Abs(p.pos[2] - bot.pos[2]);
|
||||||
|
if (curDist >= dist) continue;
|
||||||
|
|
||||||
|
dist = curDist;
|
||||||
|
bot.foundPos = p.pos;
|
||||||
|
bot.foundRot = p.rot;
|
||||||
|
bot.movement = true;
|
||||||
|
|
||||||
|
bot.rot[1] = (byte)(255 - bot.foundRot[1]);
|
||||||
|
if (bot.foundRot[0] < 128)
|
||||||
|
bot.rot[0] = (byte)(bot.foundRot[0] + 128);
|
||||||
|
else
|
||||||
|
bot.rot[0] = (byte)(bot.foundRot[0] - 128);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,15 +74,11 @@ namespace MCGalaxy {
|
|||||||
#region Script handling
|
#region Script handling
|
||||||
|
|
||||||
void BotTimerFunc(object sender, ElapsedEventArgs e) {
|
void BotTimerFunc(object sender, ElapsedEventArgs e) {
|
||||||
ushort x = (ushort)Math.Round((decimal)pos[0] / 32);
|
if (kill) Instructions.DoKill(this);
|
||||||
ushort y = (ushort)((pos[1] - 33) / 32);
|
|
||||||
ushort z = (ushort)Math.Round((decimal)pos[2] / 32);
|
|
||||||
|
|
||||||
if (kill) DoKill(x, y, z);
|
|
||||||
movement = false;
|
movement = false;
|
||||||
|
|
||||||
if (Waypoints.Count == 0) {
|
if (Waypoints.Count == 0) {
|
||||||
if (hunt) DoHunt();
|
if (hunt) Instructions.DoHunt(this);
|
||||||
} else {
|
} else {
|
||||||
bool doNextInstruction = !DoInstruction();
|
bool doNextInstruction = !DoInstruction();
|
||||||
if (cur == Waypoints.Count) cur = 0;
|
if (cur == Waypoints.Count) cur = 0;
|
||||||
@ -119,52 +115,42 @@ namespace MCGalaxy {
|
|||||||
void MoveTimerFunc(object sender, ElapsedEventArgs e) {
|
void MoveTimerFunc(object sender, ElapsedEventArgs e) {
|
||||||
moveTimer.Interval = Server.updateTimer.Interval / movementSpeed;
|
moveTimer.Interval = Server.updateTimer.Interval / movementSpeed;
|
||||||
if (!movement) return;
|
if (!movement) return;
|
||||||
int newNum;
|
|
||||||
|
|
||||||
if ((pos[1] - 19) % 32 != 0 && !jumping)
|
if ((pos[1] - 19) % 32 != 0 && !jumping)
|
||||||
{
|
|
||||||
pos[1] = (ushort)((pos[1] + 19) - (pos[1] % 32));
|
pos[1] = (ushort)((pos[1] + 19) - (pos[1] % 32));
|
||||||
}
|
|
||||||
|
|
||||||
ushort x = (ushort)Math.Round((decimal)(pos[0] - 16) / 32);
|
ushort x = (ushort)Math.Round((decimal)(pos[0] - 16) / 32);
|
||||||
ushort y = (ushort)((pos[1] - 64) / 32);
|
ushort y = (ushort)((pos[1] - 64) / 32);
|
||||||
ushort z = (ushort)Math.Round((decimal)(pos[2] - 16) / 32);
|
ushort z = (ushort)Math.Round((decimal)(pos[2] - 16) / 32);
|
||||||
|
int dx = Math.Sign(foundPos[0] - pos[0]), dz = Math.Sign(foundPos[2] - pos[2]);
|
||||||
|
|
||||||
byte b = Block.Convert(level.GetTile(x, y, z));
|
byte b = Block.Convert(level.GetTile(x, y, z));
|
||||||
byte b1, b2, b3;//, b4;
|
byte b1, b2, b3;
|
||||||
|
|
||||||
if (Block.Walkthrough(b) && !jumping)
|
if (Block.Walkthrough(b) && !jumping)
|
||||||
{
|
|
||||||
pos[1] = (ushort)(pos[1] - 32);
|
pos[1] = (ushort)(pos[1] - 32);
|
||||||
}
|
|
||||||
|
|
||||||
y = (ushort)((pos[1] - 64) / 32); //Block below feet
|
y = (ushort)((pos[1] - 64) / 32); //Block below feet
|
||||||
|
|
||||||
newNum = level.PosToInt((ushort)(x + Math.Sign(foundPos[0] - pos[0])), y, (ushort)(z + Math.Sign(foundPos[2] - pos[2])));
|
int index = level.PosToInt((ushort)(x + dx), y, (ushort)(z + dz));
|
||||||
b = Block.Convert(level.GetTile(newNum));
|
b = Block.Convert(level.GetTile(index));
|
||||||
b1 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 1, 0)));
|
b1 = Block.Convert(level.GetTile(level.IntOffset(index, 0, 1, 0)));
|
||||||
b2 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 2, 0)));
|
b2 = Block.Convert(level.GetTile(level.IntOffset(index, 0, 2, 0)));
|
||||||
b3 = Block.Convert(level.GetTile(level.IntOffset(newNum, 0, 3, 0)));
|
b3 = Block.Convert(level.GetTile(level.IntOffset(index, 0, 3, 0)));
|
||||||
|
|
||||||
if (Block.Walkthrough(b2) && Block.Walkthrough(b3) && !Block.Walkthrough(b1))
|
if (Block.Walkthrough(b2) && Block.Walkthrough(b3) && !Block.Walkthrough(b1)) {
|
||||||
{ //Get ready to go up step
|
pos[0] += (ushort)dx; // Get ready to go up step
|
||||||
pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]);
|
|
||||||
pos[1] += (ushort)32;
|
pos[1] += (ushort)32;
|
||||||
pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]);
|
pos[2] += (ushort)dz;
|
||||||
}
|
} else if (Block.Walkthrough(b1) && Block.Walkthrough(b2)) {
|
||||||
else if (Block.Walkthrough(b1) && Block.Walkthrough(b2))
|
pos[0] += (ushort)dx; // Stay on current level
|
||||||
{ //Stay on current level
|
pos[2] += (ushort)dz;
|
||||||
pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]);
|
} else if (Block.Walkthrough(b) && Block.Walkthrough(b1)) {
|
||||||
pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]);
|
pos[0] += (ushort)dx; // Drop a level
|
||||||
}
|
|
||||||
else if (Block.Walkthrough(b) && Block.Walkthrough(b1))
|
|
||||||
{ //Drop a level
|
|
||||||
pos[0] += (ushort)Math.Sign(foundPos[0] - pos[0]);
|
|
||||||
pos[1] -= (ushort)32;
|
pos[1] -= (ushort)32;
|
||||||
pos[2] += (ushort)Math.Sign(foundPos[2] - pos[2]);
|
pos[2] += (ushort)dz;
|
||||||
}
|
}
|
||||||
|
|
||||||
x = (ushort)Math.Round((decimal)(pos[0] - 16) / (decimal)32);
|
/*x = (ushort)Math.Round((decimal)(pos[0] - 16) / (decimal)32);
|
||||||
y = (ushort)((pos[1] - 64) / 32);
|
y = (ushort)((pos[1] - 64) / 32);
|
||||||
z = (ushort)Math.Round((decimal)(pos[2] - 16) / (decimal)32);
|
z = (ushort)Math.Round((decimal)(pos[2] - 16) / (decimal)32);
|
||||||
|
|
||||||
@ -172,7 +158,7 @@ namespace MCGalaxy {
|
|||||||
b2 = Block.Convert(level.GetTile(x, (ushort)(y + 2), z));
|
b2 = Block.Convert(level.GetTile(x, (ushort)(y + 2), z));
|
||||||
b3 = Block.Convert(level.GetTile(x, y, z));
|
b3 = Block.Convert(level.GetTile(x, y, z));
|
||||||
|
|
||||||
/*
|
|
||||||
if ((ushort)(foundPos[1] / 32) > y) {
|
if ((ushort)(foundPos[1] / 32) > y) {
|
||||||
if (b1 == Block.water || b1 == Block.waterstill || b1 == Block.lava || b1 == Block.lavastill) {
|
if (b1 == Block.water || b1 == Block.waterstill || b1 == Block.lava || b1 == Block.lavastill) {
|
||||||
if (Block.Walkthrough(b2)) {
|
if (Block.Walkthrough(b2)) {
|
||||||
@ -187,37 +173,6 @@ namespace MCGalaxy {
|
|||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoKill(ushort x, ushort y, ushort z) {
|
|
||||||
Player[] players = PlayerInfo.Online.Items;
|
|
||||||
foreach (Player p in players) {
|
|
||||||
if ((ushort)(p.pos[0] / 32) == x
|
|
||||||
&& Math.Abs((ushort)(p.pos[1] / 32) - y) < 2
|
|
||||||
&& (ushort)(p.pos[2] / 32) == z) {
|
|
||||||
p.HandleDeath(Block.Zero);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void DoHunt() {
|
|
||||||
int foundNum = (32 * 75);
|
|
||||||
Player[] players = PlayerInfo.Online.Items;
|
|
||||||
foreach (Player p in players) {
|
|
||||||
if (p.level != level || p.invincible) continue;
|
|
||||||
|
|
||||||
int currentNum = Math.Abs(p.pos[0] - pos[0]) + Math.Abs(p.pos[1] - pos[1]) + Math.Abs(p.pos[2] - pos[2]);
|
|
||||||
if (currentNum < foundNum)
|
|
||||||
{
|
|
||||||
foundNum = currentNum;
|
|
||||||
foundPos = p.pos;
|
|
||||||
foundRot = p.rot;
|
|
||||||
movement = true;
|
|
||||||
rot[1] = (byte)(255 - foundRot[1]);
|
|
||||||
if (foundRot[0] < 128) rot[0] = (byte)(foundRot[0] + 128);
|
|
||||||
else rot[0] = (byte)(foundRot[0] - 128);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public void SetPos(ushort x, ushort y, ushort z, byte rotx, byte roty) {
|
public void SetPos(ushort x, ushort y, ushort z, byte rotx, byte roty) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user