Skip to content

Commit

Permalink
Working build
Browse files Browse the repository at this point in the history
  • Loading branch information
White committed Jul 1, 2015
1 parent 842fe3c commit a3abe3f
Show file tree
Hide file tree
Showing 335 changed files with 377,027 additions and 163,255 deletions.
92 changes: 92 additions & 0 deletions Extensions/EnumerationExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using System;
using System.Runtime.CompilerServices;

namespace Extensions
{
public static class EnumerationExtensions
{
public static bool Has<T>(this Enum value, T check)
{
Type type = value.GetType();
EnumerationExtensions._Value __Value = new EnumerationExtensions._Value((object)check, type);
if (__Value.Signed.HasValue)
{
return (Convert.ToInt64(value) & __Value.Signed.Value) == __Value.Signed.Value;
}
if (!__Value.Unsigned.HasValue)
{
return false;
}
return (Convert.ToUInt64(value) & __Value.Unsigned.Value) == __Value.Unsigned.Value;
}

public static T Include<T>(this Enum value, T append)
{
Type type = value.GetType();
object num = value;
EnumerationExtensions._Value __Value = new EnumerationExtensions._Value((object)append, type);
if (__Value.Signed.HasValue)
{
num = Convert.ToInt64(value) | __Value.Signed.Value;
}
else if (__Value.Unsigned.HasValue)
{
num = Convert.ToUInt64(value) | __Value.Unsigned.Value;
}
return (T)Enum.Parse(type, num.ToString());
}

public static bool Missing<T>(this Enum obj, T value)
{
return !obj.Has<T>(value);
}

public static T Remove<T>(this Enum value, T remove)
{
Type type = value.GetType();
object num = value;
EnumerationExtensions._Value __Value = new EnumerationExtensions._Value((object)remove, type);
if (__Value.Signed.HasValue)
{
num = Convert.ToInt64(value) & ~__Value.Signed.Value;
}
else if (__Value.Unsigned.HasValue)
{
num = Convert.ToUInt64(value) & ~__Value.Unsigned.Value;
}
return (T)Enum.Parse(type, num.ToString());
}

private class _Value
{
private static Type _UInt64;

private static Type _UInt32;

public long? Signed;

public ulong? Unsigned;

static _Value()
{
EnumerationExtensions._Value._UInt64 = typeof(ulong);
EnumerationExtensions._Value._UInt32 = typeof(long);
}

public _Value(object value, Type type)
{
if (!type.IsEnum)
{
throw new ArgumentException("Value provided is not an enumerated type!");
}
Type underlyingType = Enum.GetUnderlyingType(type);
if (!underlyingType.Equals(EnumerationExtensions._Value._UInt32) && !underlyingType.Equals(EnumerationExtensions._Value._UInt64))
{
this.Signed = new long?(Convert.ToInt64(value));
return;
}
this.Unsigned = new ulong?(Convert.ToUInt64(value));
}
}
}
}
41 changes: 14 additions & 27 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
using System.Reflection;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Properties")]
[assembly: AssemblyCompany("Re-Logic")]
[assembly: AssemblyCopyright("Copyright © Re-Logic 2015")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Properties")]
[assembly: AssemblyCopyright("Copyright © 2012-2014")]
[assembly: AssemblyFileVersion("1.3.0.1")]
[assembly: AssemblyProduct("Terraria")]
[assembly: AssemblyTitle("Terraria")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: AssemblyVersion("1.3.0.1")]
[assembly: CompilationRelaxations(8)]
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("e090131f-b5df-4785-b79e-1417d5329bda")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.15.0.0")]
[assembly: AssemblyFileVersion("1.15.0.0")]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: Guid("f571b16a-2c9b-44ab-b115-7c762c9e4e7e")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows=true)]
Binary file not shown.
Binary file not shown.
205 changes: 205 additions & 0 deletions Terraria/Achievements/Achievement.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Threading;
using Terraria.Social;
using Terraria.Social.Base;

namespace Terraria.Achievements
{
[JsonObject(MemberSerialization.OptIn)]
public class Achievement
{
private static int _totalAchievements;

public readonly string Name;

public readonly string FriendlyName;

public readonly string Description;

public readonly int Id;

private AchievementCategory _category;

private IAchievementTracker _tracker;

[JsonProperty("Conditions")]
private Dictionary<string, AchievementCondition> _conditions;

private int _completedCount;

public AchievementCategory Category
{
get
{
return this._category;
}
}

public bool HasTracker
{
get
{
return this._tracker != null;
}
}

public bool IsCompleted
{
get
{
return this._completedCount == this._conditions.Count;
}
}

static Achievement()
{
}

public Achievement(string name, string friendlyName, string description)
{
int num = Achievement._totalAchievements;
Achievement._totalAchievements = num + 1;
this.Id = num;
this._conditions = new Dictionary<string, AchievementCondition>();
this.Name = name;
this.FriendlyName = friendlyName;
this.Description = description;
}

public void AddCondition(AchievementCondition condition)
{
this._conditions[condition.Name] = condition;
condition.OnComplete += new AchievementCondition.AchievementUpdate(this.OnConditionComplete);
}

public void AddConditions(params AchievementCondition[] conditions)
{
for (int i = 0; i < (int)conditions.Length; i++)
{
this.AddCondition(conditions[i]);
}
}

public void ClearProgress()
{
this._completedCount = 0;
foreach (KeyValuePair<string, AchievementCondition> _condition in this._conditions)
{
_condition.Value.Clear();
}
if (this._tracker != null)
{
this._tracker.Clear();
}
}

public void ClearTracker()
{
this._tracker = null;
}

public AchievementCondition GetCondition(string conditionName)
{
AchievementCondition achievementCondition;
if (this._conditions.TryGetValue(conditionName, out achievementCondition))
{
return achievementCondition;
}
return null;
}

private IAchievementTracker GetConditionTracker(string name)
{
return this._conditions[name].GetAchievementTracker();
}

public IAchievementTracker GetTracker()
{
return this._tracker;
}

public void Load(Dictionary<string, JObject> conditions)
{
AchievementCondition achievementCondition;
foreach (KeyValuePair<string, JObject> condition in conditions)
{
if (!this._conditions.TryGetValue(condition.Key, out achievementCondition))
{
continue;
}
achievementCondition.Load(condition.Value);
if (!achievementCondition.IsCompleted)
{
continue;
}
Achievement achievement = this;
achievement._completedCount = achievement._completedCount + 1;
}
if (this._tracker != null)
{
this._tracker.Load();
}
}

private void OnConditionComplete(AchievementCondition condition)
{
Achievement achievement = this;
achievement._completedCount = achievement._completedCount + 1;
if (this._completedCount == this._conditions.Count)
{
if (this._tracker == null && SocialAPI.Achievements != null)
{
SocialAPI.Achievements.CompleteAchievement(this.Name);
}
if (this.OnCompleted != null)
{
this.OnCompleted(this);
}
}
}

public void SetCategory(AchievementCategory category)
{
this._category = category;
}

public void UseConditionsCompletedTracker()
{
ConditionsCompletedTracker conditionsCompletedTracker = new ConditionsCompletedTracker();
foreach (KeyValuePair<string, AchievementCondition> _condition in this._conditions)
{
conditionsCompletedTracker.AddCondition(_condition.Value);
}
this.UseTracker(conditionsCompletedTracker);
}

public void UseConditionsCompletedTracker(params string[] conditions)
{
ConditionsCompletedTracker conditionsCompletedTracker = new ConditionsCompletedTracker();
for (int i = 0; i < (int)conditions.Length; i++)
{
string str = conditions[i];
conditionsCompletedTracker.AddCondition(this._conditions[str]);
}
this.UseTracker(conditionsCompletedTracker);
}

private void UseTracker(IAchievementTracker tracker)
{
tracker.ReportAs(string.Concat("STAT_", this.Name));
this._tracker = tracker;
}

public void UseTrackerFromCondition(string conditionName)
{
this.UseTracker(this.GetConditionTracker(conditionName));
}

public event Achievement.AchievementCompleted OnCompleted;

public delegate void AchievementCompleted(Achievement achievement);
}
}
13 changes: 13 additions & 0 deletions Terraria/Achievements/AchievementCategory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System;

namespace Terraria.Achievements
{
public enum AchievementCategory
{
None = -1,
Slayer = 0,
Collector = 1,
Explorer = 2,
Challenger = 3
}
}
Loading

0 comments on commit a3abe3f

Please sign in to comment.