This repository has been archived by the owner on Mar 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cyral
committed
Jul 3, 2018
1 parent
3545000
commit 4b2e8c7
Showing
1,322 changed files
with
42,244 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
#region Usings | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using TomShane.Neoforce.Controls; | ||
using ZarknorthClient.Interface; | ||
#endregion | ||
|
||
namespace ZarknorthClient | ||
{ | ||
public class Achievement | ||
{ | ||
/// <summary> | ||
/// List of all achievements possible | ||
/// </summary> | ||
public static List<Achievement> AchievementList; | ||
/// <summary> | ||
/// The current achivement status popup | ||
/// </summary> | ||
public static AchievementStatusBox StatusBox; | ||
|
||
/// <summary> | ||
/// Name of the achievement, Ex, "Jump for George" or "Thats my Jam!" | ||
/// </summary> | ||
public string Name { get; private set; } | ||
/// <summary> | ||
/// Short description of the achievement | ||
/// </summary> | ||
public string Description { get; private set; } | ||
|
||
/// <summary> | ||
/// Item prizes to give out | ||
/// </summary> | ||
public List<Slot> Prizes { get; private set; } | ||
|
||
/// <summary> | ||
/// Amount of achievment points it is worth | ||
/// </summary> | ||
public double Points { get; private set; } | ||
|
||
/// <summary> | ||
/// Money payout to give | ||
/// </summary> | ||
public int Money { get; private set; } | ||
|
||
/// <summary> | ||
/// If the achievment has been earned yet | ||
/// </summary> | ||
public bool Achieved { get; set; } | ||
|
||
/// <summary> | ||
/// ID used for loading and saving | ||
/// </summary> | ||
public byte ID { get; private set; } | ||
|
||
public static Achievement Chop, Torch, PickUp, ReadSign, Jump, Music; | ||
|
||
/// <summary> | ||
/// Creates a new instance of an achievement | ||
/// </summary> | ||
/// <param name="name">Name of the achievement</param> | ||
/// <param name="description">Short description</param> | ||
public Achievement(string name, string description) | ||
{ | ||
Name = name; | ||
Description = description; | ||
Prizes = new List<Slot>(); | ||
Achieved = false; | ||
ID = (byte)AchievementList.Count(); | ||
|
||
AchievementList.Add(this); | ||
} | ||
/// <summary> | ||
/// Creates a new achivement lists and adds the achivements | ||
/// </summary> | ||
static Achievement() | ||
{ | ||
AchievementList = new List<Achievement>(); | ||
Init(); | ||
} | ||
/// <summary> | ||
/// Add all of the achivement configs here | ||
/// </summary> | ||
public static void Init() | ||
{ | ||
// | ||
// NOTICE: Add ALL new achievements to the end of the file, DO NOT remove achivements in production code (after release) it will mess up ID's | ||
// | ||
Jump = new Achievement("Jump for George!", "Take your first jump!") | ||
{ | ||
//Prize = Item.Diamond, | ||
Points = 1, | ||
}; | ||
Chop = new Achievement("Choppin' time!", "Chop down your first tree") | ||
{ | ||
Prizes = new List<Slot> { new Slot(Item.WoodPlank,10) }, | ||
Points = 1, | ||
}; | ||
PickUp = new Achievement("Pick em' Up!", "Pick up your first item drop!") | ||
{ | ||
Points = 1, | ||
}; | ||
Torch = new Achievement("Light the way!", "Place a torch for light!") | ||
{ | ||
Prizes = new List<Slot> { new Slot(Item.Stick, 5), new Slot(Item.Coal,5) }, | ||
Points = 1, | ||
Money = 10, | ||
}; | ||
ReadSign = new Achievement("Good reading", "Read a sign") | ||
{ | ||
Points = 1, | ||
}; | ||
Music = new Achievement("That's my jam!", "Play a note on a musical instrument") | ||
{ | ||
Points = 5.0, | ||
}; | ||
//ReadSign = new Achievement("Get Building!", "Place your first block") | ||
//{ | ||
// Prize = Item.Diamond, | ||
//}; | ||
} | ||
/// <summary> | ||
/// Checks to see if the achievement has been earned before, if not mark it off and open a popup | ||
/// </summary> | ||
/// <param name="achievement">The achievement earned</param> | ||
public static void Show(Achievement achievement) | ||
{ | ||
//If we have not gotten this achivement before | ||
if (!achievement.Achieved) | ||
{ | ||
//..Now we have | ||
achievement.Achieved = true; | ||
|
||
//Create and add the popup | ||
StatusBox = new AchievementStatusBox(Game.level.game.Manager, achievement); | ||
StatusBox.Init(); | ||
Game.level.game.Manager.Add(StatusBox); | ||
|
||
//Give the user the prizes, points and payout | ||
foreach (Slot i in achievement.Prizes) //Foreach prize | ||
for (int j = 0; j < i.Stack; j++) //Stack size | ||
Game.level.Players[0].AddToInventory(i.Item); //Give item | ||
Game.level.Players[0].achievementPoints += achievement.Points; //Add points | ||
Game.level.Players[0].Pay(achievement.Money); //Pay player | ||
|
||
//Search controls to find any open achivement logs, if found, update them. | ||
IEnumerable<Control> controlList = Game.level.game.Manager.Controls.Where(x => x is TaskAchievementLog); | ||
foreach (Control c in controlList) | ||
(c as TaskAchievementLog).ResetItems(Game.level.game.Manager); | ||
|
||
//If there are more achivements on screen, move this box up a bit so they don't overlap | ||
controlList = Game.level.game.Manager.Controls.Where(x => x is AchievementStatusBox); | ||
StatusBox.FinalTop -= (controlList.Count() - 1) * (StatusBox.Height + 12); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using Microsoft.Xna.Framework; | ||
|
||
namespace ZarknorthClient | ||
{ | ||
public class QueueItem | ||
{ | ||
public Action Action { get; set; } | ||
public TimeSpan Delay { get; private set; } | ||
public DateTime Timestamp { get; private set; } | ||
public bool UseThread { get; private set; } | ||
public bool Dispose { get; set; } | ||
|
||
/// <summary> | ||
/// Creates a new Queueable item | ||
/// </summary> | ||
/// <param name="action">The code to be run</param> | ||
/// <param name="delay">The delay before running</param> | ||
/// <param name="threaded">If the code should be executed in a new thread</param> | ||
public QueueItem(Action action, float delay = 0, bool threaded = false, bool dispose = true) | ||
{ | ||
Action = action; | ||
Delay = TimeSpan.FromMilliseconds(delay); | ||
UseThread = threaded; | ||
Timestamp = DateTime.Now; | ||
Dispose = true; | ||
} | ||
public void Reload() | ||
{ | ||
Timestamp = DateTime.Now; | ||
} | ||
} | ||
public class ActionQueue | ||
{ | ||
//Properties | ||
public bool Enabled { get; set; } | ||
|
||
//Fields | ||
private List<QueueItem> queue; | ||
private Thread monitor; | ||
|
||
/// <summary> | ||
/// Creates a new ActionQueue object for processing actions after time periods | ||
/// </summary> | ||
public ActionQueue() | ||
{ | ||
queue = new List<QueueItem>(); | ||
monitor = new Thread(delegate() | ||
{ | ||
while (true) | ||
{ | ||
if (Enabled) | ||
Process(); | ||
Thread.Sleep(16); | ||
} | ||
}); | ||
monitor.IsBackground = true; | ||
monitor.Start(); | ||
Enabled = true; | ||
} | ||
public void Enqueue(QueueItem action) | ||
{ | ||
queue.Add(action); | ||
} | ||
public void Process() | ||
{ | ||
for (int i = queue.Count - 1; i >= 0; i--) | ||
{ | ||
QueueItem item = queue[i]; | ||
if (DateTime.Now > item.Timestamp + item.Delay) | ||
{ | ||
if (item.UseThread) | ||
new Thread(delegate() { item.Action.Invoke(); }).Start(); | ||
else | ||
item.Action.Invoke(); | ||
if (item.Dispose) | ||
queue.RemoveAt(i); | ||
else | ||
item.Reload(); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
| ||
using System; | ||
using Microsoft.Xna.Framework.Graphics; | ||
|
||
namespace ZarknorthClient | ||
{ | ||
/// <summary> | ||
/// Represents an animated texture. | ||
/// </summary> | ||
/// <remarks> | ||
/// Currently, this class assumes that each frame of animation is | ||
/// as wide as each animation is tall. The number of frames in the | ||
/// animation are inferred from this. | ||
/// </remarks> | ||
public class Animation | ||
{ | ||
/// <summary> | ||
/// All frames in the animation arranged horizontally. | ||
/// </summary> | ||
public Texture2D Texture | ||
{ | ||
get { return texture; } | ||
} | ||
Texture2D texture; | ||
|
||
/// <summary> | ||
/// Duration of time to show each frame. | ||
/// </summary> | ||
public float FrameTime | ||
{ | ||
get { return frameTime; } | ||
} | ||
float frameTime; | ||
|
||
/// <summary> | ||
/// When the end of the animation is reached, should it | ||
/// continue playing from the beginning? | ||
/// </summary> | ||
public bool IsLooping | ||
{ | ||
get { return isLooping; } | ||
} | ||
bool isLooping; | ||
|
||
/// <summary> | ||
/// Gets the number of frames in the animation. | ||
/// </summary> | ||
public int FrameCount | ||
{ | ||
get { return Texture.Width / FrameWidth; } | ||
} | ||
|
||
/// <summary> | ||
/// Gets the width of a frame in the animation. | ||
/// </summary> | ||
public int FrameWidth; | ||
|
||
|
||
/// <summary> | ||
/// Gets the height of a frame in the animation. | ||
/// </summary> | ||
public int FrameHeight; | ||
|
||
|
||
/// <summary> | ||
/// Constructors a new animation. | ||
/// </summary> | ||
public Animation(Texture2D texture, float frameTime, bool isLooping,int Width = 0,int Height = 0) | ||
{ | ||
this.texture = texture; | ||
this.frameTime = frameTime; | ||
this.isLooping = isLooping; | ||
if (Width != 0) | ||
{ | ||
FrameHeight = Height; | ||
FrameWidth = Width; | ||
} | ||
else | ||
{ | ||
FrameHeight = texture.Height; | ||
FrameWidth = FrameHeight; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.