Skip to content

Instantly share code, notes, and snippets.

@MrBluePotato
Last active January 2, 2016 08:39
Show Gist options
  • Save MrBluePotato/8278112 to your computer and use it in GitHub Desktop.
Save MrBluePotato/8278112 to your computer and use it in GitHub Desktop.
// Modifications Copyright (c) 2013 Michael Cummings <[email protected]>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
// * Neither the name of AtomicCraft or the names of its
// contributors may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace fCraft
{
class PropHunt
{
private string[] blockId = {"1", "2", "4", "5", "7", "12", "13", "17", "19", "64", "65"};
private Random randBlock = new Random();
//Time stuff
private static SchedulerTask task_;
private static SchedulerTask _task;
private DateTime startTime;
public static DateTime lastChecked;
public static int timeLeft = 0;
public static int timeLimit = 300;
public static int timeDelay = 10;
public static bool isOn = false;
public static PropHunt instance;
private static World _world;
public static List<Player> PropHuntPlayers = new List<Player>();
public PropHunt (World world)
{
startTime = DateTime.UtcNow;
_world = world;
task_ = new SchedulerTask(Interval, true).RunForever(TimeSpan.FromSeconds(1));
_task = new SchedulerTask(Interval, true).RunForever(TimeSpan.FromSeconds(1));
}
public void Start()
{
_world.gameMode = GameMode.PropHunt;
startTime = DateTime.UtcNow;
foreach (Player p in _world.Players)
{
p.Model = blockId[randBlock.Next(0, blockId.Length)];
}
}
public void Interval(SchedulerTask task)
{
//Temp debug message
//Server.Message("Doing stuff");
//check to stop Interval
if (_world.gameMode != GameMode.PropHunt || _world == null)
{
_world = null;
task.Stop();
return;
}
if (!isOn)
{
if (_world.Players.Count() < 0 /*2*/) //in case players leave the world or disconnect during the start delay
{
_world.Players.Message("&WPropHunt&s requires at least (4) people to play.");
}
if (startTime != null && (DateTime.UtcNow - startTime).TotalSeconds > timeDelay)
{
foreach (Player p in _world.Players)
{
beginGame(p);
chooseSeeker();
}
Player.Moving += CheckIdles;
//Player.Moving += PlayerMovedTag;
isOn = true;
lastChecked = DateTime.UtcNow; //used for intervals
//Temp debug message
Server.Message("It is on and stuff...");
return;
}
}
/*if (isOn && (DateTime.UtcNow - lastChecked).TotalSeconds > 10) //check if players left the world, forfeits if no players of that team left
{
if (_world.Players.Count(player => player.Info.isInfected) == _world.Players.Count())
{
ZombiesWin();
return;
}
if (_world.Players.Count(player => player.Info.isInfected) == 0 && _world.Players.Count() > 0)
{
HumansWin();
return;
}
}*/
timeLeft = Convert.ToInt16(((timeDelay + timeLimit) - (DateTime.Now - startTime).TotalSeconds));
if (lastChecked != null && (DateTime.UtcNow - lastChecked).TotalSeconds > 29.9 && timeLeft <= timeLimit)
{
_world.Players.Message("There are currently {0} human(s) and {1} zombie(s) left on {2}", _world.Players.Count() - _world.Players.Count(player => player.isInfected), _world.Players.Count(player => player.isInfected), _world.ClassyName);
}
}
public static void beginGame(Player player)
{
player.isPlayingPropHunt = true;
PropHuntPlayers.Add(player);
//Temp debug message
Server.Message("Beginning game....");
}
// Choose a random player as the seeker
public static void chooseSeeker()
{
Random randNumber = new Random();
int randSeeker = randNumber.Next(0, _world.Players.Length);
Player seeker = _world.Players[randSeeker];
if (_world.Players.Count(player => player.isSeeker) == 0)
{
seeker.Message("&cYou were chosen as the seeker!");
}
}
/*public static void PlayerMovedSolid(object var, fCraft.Events.PlayerMovingEventArgs e)
{
if (!e.Player.isSolidBlock)
{
TimeSpan idle = e.Player.IdleTime;
//Player has to be not move for 5 seconds
if (idle.TotalSeconds > 5)
{
Server.Message("{0} is idle!", e.Player.ClassyName);
e.Player.Info.IsHidden = true;
e.Player.isSolidBlock = true;
//Gets the coords of the player
short x = (short)(e.Player.Position.X / 32 * 32 + 16);
short y = (short)(e.Player.Position.Y / 32 * 32 + 16);
short z = (short)(e.Player.Position.Z / 32 * 32);
Vector3I Pos = new Vector3I(e.Player.Position.X / 32, e.Player.Position.Y / 32, (e.Player.Position.Z - 32) / 32);
//Converts player's model block into Block.*blockname*
Block playerBlock = Map.GetBlockByName(e.Player.Model);
//Places the block at the players current location
BlockUpdate blockUpdate = new BlockUpdate(null, Pos, playerBlock);
e.Player.World.Map.QueueUpdate(blockUpdate);
e.Player.WorldMap.SetBlock(Pos, playerBlock);
e.Player.Message("&cYou are now a solid block. Don't move!");
}
}
else
{
// We need to have block positions, so we divide by 32
Vector3I oldPos = new Vector3I(e.OldPosition.X / 32, e.OldPosition.Y / 32, e.OldPosition.Z / 32);
Vector3I newPos = new Vector3I(e.NewPosition.X / 32, e.NewPosition.Y / 32, e.NewPosition.Z / 32);
// Check if the player actually moved and not just rotated
if ((oldPos.X != newPos.X) || (oldPos.Y != newPos.Y) || (oldPos.Z != newPos.Z))
{
e.Player.Message("You are no longer a solid block!");
e.Player.isSolidBlock = false;
e.Player.Info.IsHidden = false;
}
}
}*/
public static void CheckIdles(object sender, fCraft.Events.PlayerMovingEventArgs e)
{
if (e.Player.IdleTime.ToSeconds() == 4 && !e.Player.isSolidBlock)
{
//Temp debug message
Server.Message("{0} is idle!", e.Player.ClassyName);
e.Player.Info.IsHidden = true;
e.Player.isSolidBlock = true;
//Gets the coords of the player
short x = (short)(e.Player.Position.X / 32 * 32 + 16);
short y = (short)(e.Player.Position.Y / 32 * 32 + 16);
short z = (short)(e.Player.Position.Z / 32 * 32);
Vector3I Pos = new Vector3I(e.Player.Position.X / 32, e.Player.Position.Y / 32, (e.Player.Position.Z - 32) / 32);
//Converts player's model block into Block.*blockname*
Block playerBlock = Map.GetBlockByName(e.Player.Model);
//Places the block at the players current location
BlockUpdate blockUpdate = new BlockUpdate(null, Pos, playerBlock);
e.Player.World.Map.QueueUpdate(blockUpdate);
e.Player.WorldMap.SetBlock(Pos, playerBlock);
e.Player.prophuntLastSolidPos = Pos;
e.Player.Message("&cYou are now a solid block. Don't move!");
}
else
{
// We need to have block positions, so we divide by 32
Vector3I oldPos = new Vector3I(e.OldPosition.X / 32, e.OldPosition.Y / 32, e.OldPosition.Z / 32);
Vector3I newPos = new Vector3I(e.NewPosition.X / 32, e.NewPosition.Y / 32, e.NewPosition.Z / 32);
// Check if the player actually moved and not just rotated
if ((oldPos.X != newPos.X) || (oldPos.Y != newPos.Y) || (oldPos.Z != newPos.Z))
{
//Remove the players block
Block airBlock = Block.Air;
e.Player.WorldMap.SetBlock(e.Player.prophuntLastSolidPos, airBlock);
BlockUpdate blockUpdate = new BlockUpdate(null, e.Player.prophuntLastSolidPos, airBlock);
e.Player.World.Map.QueueUpdate(blockUpdate);
//Do the other stuff
e.Player.Message("You are no longer a solid block!");
e.Player.isSolidBlock = false;
e.Player.Info.IsHidden = false;
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment