/*
* PlayerObject.cs
* Authors: Karl Orosz, Brian Chesbrough
* Copyright (c) 2007-2008 Cornell University
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
namespace StarJack
{
///
/// The Player
///
public class PlayerObject : GameObject
{
public const int MAX_POWER = 100;
public const int CAUGTDRAIN = 20;
public const int HACKDRAIN = 10;
private int mCurPower =100;
public int Power{
get{return mCurPower;}
set
{
mCurPower = value;
if (mCurPower > MAX_POWER)
{
mCurPower = MAX_POWER;
}
else if (mCurPower < 0)
{
mCurPower = 0;
}
}
}
public List mEventList;
public List mLogList;
public int mCloakCount = 0;
private const int mCloakCooldown = 5;
public const int CloakTime = 16;
public Color CloakColor = new Color(255, 255, 255, 150);
private CloakState mCurCloakState = CloakState.Available;
public CloakState CurrentCloakState{
get { return mCurCloakState; }
}
public enum CloakState
{
Cloaked,
Available,
CoolDown
}
public enum PlayerState
{
Caught,
Cloaked,
Normal,
NoPower
}
private PlayerState mPState;
public PlayerState StateOfPlayer
{
get { return mPState; }
set { mPState = value; }
}
private List mTraps;
private int mTrapCount = 25;
private int mCurTrap;
public PlayerObject(String assetName, bool tileMode)
:base(assetName, tileMode)
{
Group = "Player";
StateOfPlayer = PlayerState.Normal;
mAnimation = new Animation();
mAnimation.Group = Group;
Depth = 0.4f;
Collision = true;
mEventList = new List();
mLogList = new List();
mCurTrap = 0;
//Adds traps
mTraps = new List();
while (mTraps.Count < mTrapCount)
{
GameObject trap = new GameObject("trap", true);
trap.TextureName = "Mine";
trap.Width = Tile.WIDTH;
trap.Height = Tile.HEIGHT;
TrapAI ai = new TrapAI();
ai.TypeSearch = typeof(Enemy);
ai.Trap = trap;
trap.AddAI(ai);
mTraps.Add(trap);
}
}
new public Room MyRoom
{
get { return base.MyRoom; }
set { foreach (GameObject go in mTraps) { go.MyRoom = value; } base.MyRoom = value; }
}
public override void LoadContent(Microsoft.Xna.Framework.Content.ContentManager content)
{
base.LoadContent(content);
foreach (GameObject go in mTraps)
{
go.LoadContent(content);
}
}
///
/// The player will attempt to inteact wil the specified position
///
///
public void Interact()
{
int[] offSet = FacingMod();
foreach (GameObject go in mRoom.PositionList[Position[0] + offSet[0], Position[1] + offSet[1]])
{
HackableObject hack = go as HackableObject;
if (hack != null)
{
hack.Hack();
}
}
}
public GameObject CanInteract()
{
int[] offSet = FacingMod();
foreach (GameObject go in mRoom.PositionList[Position[0] + offSet[0], Position[1] + offSet[1]])
{
HackableObject hack = go as HackableObject;
if (hack != null)
{
return hack;
}
}
return null;
}
public override void Update(Microsoft.Xna.Framework.GameTime time)
{
if (Detected)
{
// Event for teleport
mLogList.Add(1);
StateOfPlayer = PlayerState.Caught;
//mRoom.State = Room.GameState.Caught;
MyAnimation.SetAnimation("Teleport");
MyAnimation.Mode = Animation.PlayMode.Once;
TurnRoutines.Add(new TurnAnimation(mAnimation));
mRoom.ChangePosition(this,mRoom.PlayerStartingPos);
Detected = false;
mCurPower -= CAUGTDRAIN;
mCloakCount = 0;
for (int i = 0; i < mRoom.GameObjects.Count; i++)
{
//If the GameObject is a LinkedObject, link it
TutorialPrompt thisPrompt = mRoom.GameObjects[i] as TutorialPrompt;
if (thisPrompt != null)
{
thisPrompt.ResetAI();
}
}
/*
if (mCurPower <= 0)
{
StateOfPlayer = PlayerState.NoPower;
}*/
}
base.Update(time);
}
public override void Draw(Microsoft.Xna.Framework.Graphics.SpriteBatch pSpriteBatch)
{
base.Draw(pSpriteBatch);
}
public override bool Move(Direction dir, bool adjustFacing)
{
bool ret = base.Move(dir, adjustFacing);
TakeTurn(0, false);
return ret;
}
public int Cloak
{
get { return mCloakCount; }
set
{
if (mCurCloakState == CloakState.Available)
{
mLogList.Add(2);
mCloakCount = value;
Detectable = false;
Color = CloakColor;
mCurCloakState = CloakState.Cloaked;
TakeTurn(0, false);
}
}
}
public override void TakeTurn(int pTurn, bool deffered)
{
if (!deffered)
{
if (mCurCloakState == CloakState.Cloaked)
{
mCloakCount--;
if (mCloakCount <= 0)
{
mLogList.Add(3);
Detectable = true;
Color = Color.White;
mCurCloakState = CloakState.CoolDown;
mCloakCount = mCloakCooldown;
}
}
else if (mCurCloakState == CloakState.CoolDown)
{
mCloakCount--;
if (mCloakCount <= 0)
{
mCurCloakState = CloakState.Available;
}
}
}
base.TakeTurn(pTurn, deffered);
base.MyRoom.TakeTurn(pTurn, deffered);
}
public void PlaceTrap(){
mRoom.RemoveAtPos(mTraps[mCurTrap]);
int[] direct = FacingMod();
int[] pos = Position.Clone() as int[];
//event for placing trap
mLogList.Add(4);
pos[0] += direct[0];
pos[1] += direct[1];
if (MyRoom.CheckCollision(mTraps[mCurTrap], pos))
{
pos[0] -= direct[0];
pos[1] -= direct[1];
}
mTraps[mCurTrap].Position = pos;
mTraps[mCurTrap].ResetAI();
mTraps[mCurTrap].AIEnable = true;
MyRoom.AddGameObject(mTraps[mCurTrap], mTraps[mCurTrap].Position);
mCurTrap += 1;
if (mCurTrap >= mTrapCount)
{
mCurTrap=0;
}
TakeTurn(0, false);
}
}
}