mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-21 00:07:30 +00:00
PvP!
This commit is contained in:
parent
cf3aa79c54
commit
56665dfdb3
1
README
1
README
@ -44,4 +44,5 @@ Current features of the server:
|
||||
- Survival & Creative
|
||||
- Awesome features in server list!
|
||||
- Players spawn and see each other moving!
|
||||
- PvP and life regeneration!
|
||||
- Multiple worlds and importing!
|
||||
|
@ -140,7 +140,7 @@ class ChunkParser{
|
||||
$Z = $z >> 4;
|
||||
$aX = $x - ($X << 4);
|
||||
$aZ = $z - ($Z << 4);
|
||||
$index = $aZ + ($aX << 4);
|
||||
$index = $aX + ($aZ << 4);
|
||||
console("[DEBUG] $x $y $z | $X $Z $index", true, true, 2);
|
||||
var_dump($this->map[$X][$Z][0][$index]);
|
||||
$block = ord($this->map[$X][$Z][0][$index]{$y});
|
||||
|
@ -382,6 +382,17 @@ class CustomPacketHandler{
|
||||
$this->raw .= Utils::writeShort($this->data["meta"]);
|
||||
}
|
||||
break;
|
||||
case MC_INTERACT:
|
||||
if($this->c === false){
|
||||
$this->data["action"] = Utils::readByte($this->get(1));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
$this->data["target"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeByte($this->data["action"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
$this->raw .= Utils::writeInt($this->data["target"]);
|
||||
}
|
||||
break;
|
||||
case MC_SET_ENTITY_DATA:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
@ -392,13 +403,22 @@ class CustomPacketHandler{
|
||||
));
|
||||
}
|
||||
break;
|
||||
case MC_SET_HEALTH: //SetHealth
|
||||
case MC_SET_HEALTH:
|
||||
if($this->c === false){
|
||||
$this->data["health"] = ord($this->get(1));
|
||||
}else{
|
||||
$this->raw .= chr($this->data["health"]);
|
||||
}
|
||||
break;
|
||||
case MC_ANIMATE:
|
||||
if($this->c === false){
|
||||
$this->data["action"] = Utils::readByte($this->get(1));
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
}else{
|
||||
$this->raw .= Utils::writeByte($this->data["action"]);
|
||||
$this->raw .= Utils::writeInt($this->data["eid"]);
|
||||
}
|
||||
break;
|
||||
case MC_RESPAWN:
|
||||
if($this->c === false){
|
||||
$this->data["eid"] = Utils::readInt($this->get(4));
|
||||
|
@ -42,6 +42,7 @@ class PocketMinecraftServer{
|
||||
$this->mapName = false;
|
||||
$this->map = false;
|
||||
$this->level = false;
|
||||
$this->difficulty = 1;
|
||||
$this->tileEntities = array();
|
||||
$this->entities = array();
|
||||
$this->custom = array();
|
||||
@ -77,6 +78,7 @@ class PocketMinecraftServer{
|
||||
$this->event("onChat", "eventHandler", true);
|
||||
|
||||
$this->action(100000, '$this->time += ceil($this->timePerSecond / 10);$this->trigger("onTimeChange", $this->time);');
|
||||
$this->action(5000000, '$this->trigger("onHealthRegeneration", 1);');
|
||||
$this->action(1000000 * 60, '$this->reloadConfig();');
|
||||
$this->action(1000000 * 60 * 10, '$this->custom = array();');
|
||||
$this->action(1000000 * 80, '$list = ""; foreach($this->clients as $c){$list .= ", ".$c->username;}$this->chat(false, count($this->clients)."/".$this->maxClients." online: ".substr($list, 2));');
|
||||
@ -168,6 +170,8 @@ class PocketMinecraftServer{
|
||||
console("[INFO] Time: ".$this->time);
|
||||
console("[INFO] Seed: ".$this->seed);
|
||||
console("[INFO] Gamemode: ".($this->gamemode === 0 ? "survival":"creative"));
|
||||
$d = array(0 => "peaceful", 1 => "easy", 2 => "normal", 3 => "hard");
|
||||
console("[INFO] Difficulty: ".$d[$this->difficulty]);
|
||||
console("[INFO] Loading map...");
|
||||
$this->map = new ChunkParser();
|
||||
if(!$this->map->loadFile($this->mapDir."chunks.dat")){
|
||||
|
@ -110,6 +110,11 @@ class Session{
|
||||
));
|
||||
++$this->counter[0];
|
||||
break;
|
||||
case "onHealthRegeneration":
|
||||
if($this->server->difficulty < 2){
|
||||
$this->server->trigger("onHealthChange", array("eid" => $this->eid, "health" => min(20, $this->data["health"] + $data)));
|
||||
}
|
||||
break;
|
||||
case "onHealthChange":
|
||||
if($data["eid"] === $this->eid){
|
||||
$this->send(0x84, array(
|
||||
@ -171,6 +176,21 @@ class Session{
|
||||
));
|
||||
++$this->counter[0];
|
||||
break;
|
||||
case "onAnimate":
|
||||
if($data["eid"] === $this->eid){
|
||||
break;
|
||||
}
|
||||
$this->send(0x84, array(
|
||||
$this->counter[0],
|
||||
0x00,
|
||||
array(
|
||||
"id" => MC_ANIMATE,
|
||||
"eid" => $data["eid"],
|
||||
"action" => $data["action"],
|
||||
),
|
||||
));
|
||||
++$this->counter[0];
|
||||
break;
|
||||
case "onChat":
|
||||
$this->send(0x84, array(
|
||||
$this->counter[0],
|
||||
@ -261,6 +281,8 @@ class Session{
|
||||
$this->evid[] = array("onEntityRemove", $this->server->event("onEntityRemove", array($this, "eventHandler")));
|
||||
$this->evid[] = array("onEntityMove", $this->server->event("onEntityMove", array($this, "eventHandler")));
|
||||
$this->evid[] = array("onHealthChange", $this->server->event("onHealthChange", array($this, "eventHandler")));
|
||||
$this->evid[] = array("onHealthRegeneration", $this->server->event("onHealthRegeneration", array($this, "eventHandler")));
|
||||
$this->evid[] = array("onAnimate", $this->server->event("onAnimate", array($this, "eventHandler")));
|
||||
$this->send(0x84, array(
|
||||
$this->counter[0],
|
||||
0x00,
|
||||
@ -369,6 +391,14 @@ class Session{
|
||||
));
|
||||
++$this->counter[0];
|
||||
break;
|
||||
case MC_INTERACT:
|
||||
if($this->server->difficulty > 0 and isset($this->server->entities[$data["target"]]) and Utils::distance($this->entity->position, $this->server->entities[$data["target"]]->position) <= 8){
|
||||
$this->server->trigger("onHealthChange", array("eid" => $data["eid"], "health" => $this->server->entities[$data["eid"]]->getHealth() - $this->server->difficulty));
|
||||
}
|
||||
break;
|
||||
case MC_ANIMATE:
|
||||
$this->server->trigger("onAnimate", array("eid" => $this->eid, "action" => $data["action"]));
|
||||
break;
|
||||
case MC_RESPAWN:
|
||||
$this->server->trigger("onHealthChange", array("eid" => $this->eid, "health" => 20));
|
||||
$this->entity->setPosition($data["x"], $data["y"], $data["z"], $data["x"], 0, 0);
|
||||
|
@ -10,6 +10,7 @@ max-players=20
|
||||
server-type=normal
|
||||
time-per-second=20
|
||||
gamemode=0
|
||||
difficulty=1
|
||||
seed=false
|
||||
level-name=false
|
||||
server-id=false
|
||||
|
@ -63,6 +63,7 @@ define("MC_CHUNK_DATA", 0x9e);
|
||||
|
||||
define("MC_PLAYER_EQUIPMENT", 0x9f);
|
||||
|
||||
define("MC_INTERACT", 0xa0);
|
||||
define("MC_USE_ITEM", 0xa1);
|
||||
define("MC_PLAYER_ACTION", 0xa2);
|
||||
define("MC_SET_ENTITY_DATA", 0xa3);
|
||||
|
@ -63,6 +63,7 @@ $dataName = array(
|
||||
|
||||
MC_PLAYER_EQUIPMENT => "PlayerEquipment",
|
||||
|
||||
MC_INTERACT => "Interact",
|
||||
MC_USE_ITEM => "UseItem",
|
||||
MC_PLAYER_ACTION => "PlayerAction",
|
||||
MC_SET_ENTITY_DATA => "SetEntityData",
|
||||
|
13
server.php
13
server.php
@ -70,6 +70,7 @@ foreach($prop as $line){
|
||||
case "max-players":
|
||||
case "port":
|
||||
case "debug":
|
||||
case "difficulty":
|
||||
case "time-per-second":
|
||||
$v = (int) $v;
|
||||
break;
|
||||
@ -226,6 +227,17 @@ function serverCommands(){
|
||||
console("[INFO] Gamemode changed to ".$server->gamemode);
|
||||
loadConfig(true);
|
||||
break;
|
||||
case "difficulty":
|
||||
$s = trim(array_shift($params));
|
||||
if($s == "" or (((int) $s) !== 0 and ((int) $s) !== 1)){
|
||||
console("[INFO] Usage: /difficulty <0 | 1>");
|
||||
break;
|
||||
}
|
||||
$config["difficulty"] = (int) $s;
|
||||
$server->difficulty = $config["difficulty"];
|
||||
console("[INFO] Difficulty changed to ".$server->difficulty);
|
||||
loadConfig(true);
|
||||
break;
|
||||
case "say":
|
||||
$s = implode(" ", $params);
|
||||
if(trim($s) == ""){
|
||||
@ -355,6 +367,7 @@ function serverCommands(){
|
||||
case "?":
|
||||
console("[INFO] /help: Show available commands");
|
||||
console("[INFO] /gamemode: Changes default gamemode");
|
||||
console("[INFO] /difficulty: Changes difficulty");
|
||||
console("[INFO] /say: Broadcasts mesages");
|
||||
console("[INFO] /time: Manages time");
|
||||
console("[INFO] /list: Lists online users");
|
||||
|
Loading…
x
Reference in New Issue
Block a user