Commit 8e85ed84 authored by Adam Leyshon's avatar Adam Leyshon
Browse files

Merge branch 'R1' into 'master'

Updates for 1.0 nightly build compatibility.

See merge request GWP/Release!2
parents c4a5587b 71dd9ecb
......@@ -29,7 +29,7 @@
<size>(3,2)</size>
<costList>
<Steel>120</Steel>
<Component>4</Component>
<ComponentIndustrial>4</ComponentIndustrial>
</costList>
<interactionCellOffset>(0,0,2)</interactionCellOffset>
<hasInteractionCell>true</hasInteractionCell>
......@@ -41,8 +41,8 @@
<comps>
<li Class="CompProperties_Power">
<compClass>CompPowerTrader</compClass>
<startElectricalFires>true</startElectricalFires>
<basePowerConsumption>200</basePowerConsumption>
<shortCircuitInRain>true</shortCircuitInRain>
</li>
<li Class="CompProperties_Flickable"/>
<li Class="CompProperties_Breakdownable"/>
......
......@@ -132,7 +132,7 @@ namespace Glitterworld_Prime
private static int AmountSendableSilver(Map map)
{
return (from t in TradeUtility.AllLaunchableThings(map)
return (from t in TradeUtility.AllLaunchableThingsForTrade(map)
where t.def == ThingDefOf.Silver
select t).Sum(t => t.stackCount);
}
......@@ -187,8 +187,7 @@ namespace Glitterworld_Prime
private Dialog_MessageBox AskRenew(Action confirm, Action cancel)
{
var text1 = string.Format("Resubscribe? This will cost {0} Silver for 1 Quadrum.",
_subscriptionMeta.SubscriptionCost);
var text1 = $"Resubscribe? This will cost {_subscriptionMeta.SubscriptionCost} Silver for 1 Quadrum.";
var text2 = "Confirm".Translate();
var text3 = "GoBack".Translate();
var text4 = "GlitterWorld Prime Subscription";
......@@ -201,7 +200,7 @@ namespace Glitterworld_Prime
var s = new StringBuilder();
s.AppendLine("Your GlitterWorld Prime Subscription has ended");
s.AppendLine("But you cannot afford to renew, The cost is: ");
s.AppendLine(string.Format("{0} Silver", _subscriptionMeta.SubscriptionCost));
s.AppendLine($"{_subscriptionMeta.SubscriptionCost} Silver");
return new Dialog_MessageBox(s.ToString(), title: "Not enough Silver");
}
......@@ -218,4 +217,4 @@ namespace Glitterworld_Prime
#endregion
}
}
\ No newline at end of file
}
......@@ -3,7 +3,7 @@
// This file was created by TwistedSoul @ TheCodeCache.net
// You are free to inspect the mod but may not modify or redistribute without my express permission.
// However! If you would like to contribute to GWP please feel free to drop me a message.
// Glitterworld Prime, DialogPrimeTrade.cs, Created 2017-11-18
// Glitterworld Prime, DialogPrimeTrade.cs, Created 2018-07-22
#endregion
......@@ -19,7 +19,7 @@ namespace Glitterworld_Prime
{
public class DialogPrimeTrade : Dialog_Trade
{
#region Fields
#region Fields
private Tradeable _cachedCurrencyTradeable;
private List<Tradeable> _cachedTradeables;
......@@ -38,8 +38,8 @@ namespace Glitterworld_Prime
public DialogPrimeTrade(Pawn playerNegotiator, ITrader trader) : base(playerNegotiator, trader)
{
TradeSession.SetupWith(trader, playerNegotiator);
closeOnEscapeKey = true;
TradeSession.SetupWith(trader, playerNegotiator, false);
closeOnCancel = true;
forcePause = true;
absorbInputAroundWindow = true;
soundAppear = SoundDefOf.CommsWindow_Open;
......@@ -217,7 +217,7 @@ namespace Glitterworld_Prime
OtherBottomButtonSize.y);
if (Widgets.ButtonText(rect10, "ResetButton".Translate(), true, false, true))
{
SoundDefOf.TickLow.PlayOneShotOnCamera(null);
SoundDefOf.Tick_Low.PlayOneShotOnCamera(null);
TradeSession.deal.Reset();
Utilities.SetTradablesPrice();
CacheTradeables();
......@@ -247,15 +247,17 @@ namespace Glitterworld_Prime
private void CacheTradeables()
{
// Get Silver
_cachedCurrencyTradeable = (from x in TradeSession.deal.AllTradeables
where x.IsCurrency
select x).FirstOrDefault();
_cachedTradeables = (from tr in TradeSession.deal.AllTradeables
where !tr.IsCurrency
where !tr.Label.NullOrEmpty() && tr.Label.ToLowerInvariant().Contains(_textFilter.ToLowerInvariant())
where _filter.DescendantThingDefs.Contains(tr.FirstThingColony?.def) || !_filterOnlyColonyItems &&
_filter.DescendantThingDefs.Contains(tr.FirstThingTrader?.def)
orderby !tr.TraderWillTrade ? -1 : 0 descending
where !tr.Label.NullOrEmpty() &&
tr.Label.ToLowerInvariant().Contains(_textFilter.ToLowerInvariant())
where _filter.DescendantThingDefs.Contains(tr.FirstThingColony?.GetInnerIfMinified().def) || !_filterOnlyColonyItems &&
_filter.DescendantThingDefs.Contains(tr.FirstThingTrader?.GetInnerIfMinified().def)
orderby tr.ThingDef.defName descending
select tr).ThenBy(tr => tr, _sorter1.Comparer).ThenBy(tr => tr, _sorter2.Comparer)
.ThenBy(tr => TransferableUIUtility.DefaultListOrderPriority(tr)).ThenBy(tr => tr.ThingDef.label)
.ThenBy(
......
......@@ -17,6 +17,7 @@ using System.Text;
using Glitterworld_Prime.ApiStructs;
using RestSharp;
using Verse;
using Steamworks;
namespace Glitterworld_Prime
{
......@@ -24,7 +25,7 @@ namespace Glitterworld_Prime
{
#region Fields
private static readonly float ApiVersion = 2.5f;
private static readonly float ClientVersion = 2.5f;
private static readonly string BaseUrl = "https://prime.thecodecache.net";
......@@ -45,7 +46,7 @@ namespace Glitterworld_Prime
CheckResponseForErrors(response);
if (response.StatusCode == HttpStatusCode.OK)
if (ApiVersion < response.Data.Version)
if (ClientVersion < response.Data.Version)
{
var d = new Dialog_MessageBox(
"This mod version is out of date. Please update before trading.", title: "GlitterWorldPrime");
......@@ -118,8 +119,7 @@ namespace Glitterworld_Prime
if (response.Data.IsSet() && response.Data.IsSoon())
{
var d = new Dialog_MessageBox(
string.Format("The server will be starting maintenance at {0} and will last {1} hour(s).",
response.Data.StartTime().ToString(), response.Data.DurationInHours()),
$"The server will be starting maintenance at {response.Data.StartTime().ToString()} and will last {response.Data.DurationInHours()} hour(s).",
title: "GlitterWorldPrime");
Find.WindowStack.Add(d);
}
......@@ -346,8 +346,11 @@ namespace Glitterworld_Prime
RestRequest request;
// Send colony metadata.
var cmd = new GlitterWorldColonyMetadata(Utilities.GetColonyFaction().Name,
Find.World.info.name, Utilities.GetCurrentMapName(map));
var cmd = new GlitterWorldColonyMetadata(
Utilities.GetColonyFaction().Name,
Find.World.info.name, Utilities.GetCurrentMapName(map),
Utilities.GetUserSteamId()
);
request = new RestRequest("/colonies/" + Utilities.GetMapComponent(map).ColonyId, Method.PUT);
......@@ -373,7 +376,9 @@ namespace Glitterworld_Prime
#endif
client.UserAgent = "GlitterWorldPrime " + Utilities.Version;
if (SteamUtility.SteamPersonaName != string.Empty && SteamUtility.SteamPersonaName != "???")
var steamId = Utilities.GetUserSteamId();
if (steamId != "")
client.UserAgent += " Steam";
else
client.UserAgent += " Standard";
......@@ -389,7 +394,7 @@ namespace Glitterworld_Prime
sw.Start();
var response = c.Execute<T>(r);
sw.Stop();
LogWriter.WriteMessage(string.Format("Request completed, Request took {0}", sw.Elapsed));
LogWriter.WriteMessage($"Request completed, Request took {sw.Elapsed}");
CheckResponseForErrors(response);
......@@ -404,8 +409,7 @@ namespace Glitterworld_Prime
sw.Start();
var response = c.Execute(r);
sw.Stop();
LogWriter.WriteMessage(string.Format("Request completed, Request took {0}",
sw.Elapsed));
LogWriter.WriteMessage($"Request completed, Request took {sw.Elapsed}");
CheckResponseForErrors(response);
return response;
}
......
......@@ -102,11 +102,12 @@ namespace Glitterworld_Prime.ApiStructs
{
}
public GlitterWorldColonyMetadata(string factionName, string planet, string baseName)
public GlitterWorldColonyMetadata(string factionName, string planet, string baseName, string steamId)
{
FactionName = factionName;
Planet = planet;
BaseName = baseName;
SteamId = steamId;
}
#endregion
......@@ -117,6 +118,8 @@ namespace Glitterworld_Prime.ApiStructs
public string FactionName { get; set; }
public string Planet { get; set; }
public string SteamId { get; set; }
#endregion
}
......
......@@ -95,18 +95,17 @@ namespace Glitterworld_Prime
try
{
if (thing.category == ThingCategory.Item && thing.thingClass.Name != "MinifiedThing" &&
TradeUtility.EverTradeable(thing))
TradeUtility.EverPlayerSellable(thing))
ThingsToRequestFromMarket.AddRange(Utilities.ComputeThingDef(thing, stuffCategories));
// Add support for Minifiable buildings
else if (thing.category == ThingCategory.Building && thing.Minifiable &&
thing.tradeability != Tradeability.Never)
thing.tradeability != Tradeability.None)
ThingsToRequestFromMarket.AddRange(Utilities.ComputeThingDef(thing, stuffCategories));
}
catch (Exception ex)
{
LogWriter.WriteErrorMessage(string.Format(
"GlitterWorldPrime failed to process ThingDef {0} for trading, it won't be tradeable.",
thing.defName));
LogWriter.WriteErrorMessage(
$"GlitterWorldPrime failed to process ThingDef {thing.defName} for trading, it won't be tradeable.");
LogWriter.WriteErrorMessage(ex.Message);
}
}
......
......@@ -18,7 +18,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\Assemblies\</OutputPath>
<DefineConstants>TRACE;DEBUG;B18</DefineConstants>
<DefineConstants>TRACE;DEBUG;B18,R1</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
......@@ -52,8 +52,14 @@
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\RimWorld1722Win_Data\Managed\Assembly-CSharp.dll</HintPath>
<Reference Include="Assembly-CSharp, Version=1.0.6783.42317, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\RimWorldWin_Data\Managed\Assembly-CSharp.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\RimWorldWin_Data\Managed\Assembly-CSharp-firstpass.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
......@@ -67,8 +73,9 @@
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\..\RimWorld1722Win_Data\Managed\UnityEngine.dll</HintPath>
<Reference Include="UnityEngine, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\RimWorldWin_Data\Managed\UnityEngine.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
......
......@@ -40,5 +40,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.1.18")]
[assembly: AssemblyFileVersion("2.2.1.18")]
[assembly: AssemblyVersion("3.0.0.0")]
[assembly: AssemblyFileVersion("3.0.0.0")]
......@@ -24,7 +24,7 @@ namespace Glitterworld_Prime
public override bool HandlesThingDef(ThingDef thingDef)
{
return thingDef.tradeability != Tradeability.Never;
return thingDef.tradeability != Tradeability.None;
}
#endregion
......@@ -52,4 +52,4 @@ namespace Glitterworld_Prime
#endregion
}
}
\ No newline at end of file
}
......@@ -106,7 +106,7 @@ namespace Glitterworld_Prime
{
//QualityCategory qc;
foreach (var t in TradeUtility.AllLaunchableThings(playerNegotiator.Map))
foreach (var t in TradeUtility.AllLaunchableThingsForTrade(playerNegotiator.Map))
//// Does this thing have a quality?
//if (t.TryGetQuality(out qc))
//{
......@@ -307,6 +307,11 @@ namespace Glitterworld_Prime
ServerSideItemData = items;
foreach (var item in items.Where(item => item.Quantity == 0))
{
Log.Message($"Skipping {item.Name} because it has 0 quantity");
}
// Fix errors when there are items but have no quantity in stock.
// Items with zero stock are downloaded because we need the price data.
foreach (var item in items.Where(item => item.Quantity > 0))
......@@ -315,6 +320,8 @@ namespace Glitterworld_Prime
// Create the Thing
thing = Utilities.CreateThing(item.Name, item.Quantity, item.StuffType);
if (thing.def.defName == "Silver") continue;
// Add support for Quality
if (!item.Quality.NullOrEmpty())
if (thing.def.HasComp(typeof(CompQuality)))
......@@ -334,7 +341,6 @@ namespace Glitterworld_Prime
item.BaseMarketValue = thing.MarketValue;
}
if (thing == null || thing.def.defName == "Silver") continue;
// Make sure changing its "stuff" doesn't reduce its hitpoints.
thing.HitPoints = thing.MaxHitPoints;
......@@ -367,6 +373,16 @@ namespace Glitterworld_Prime
foreach (var t in _goods) t.Destroy();
}
public Faction GetFaction()
{
throw new NotImplementedException();
}
public FloatMenuOption CommFloatMenuOption(Building_CommsConsole console, Pawn negotiator)
{
throw new NotImplementedException();
}
#endregion
}
}
\ No newline at end of file
}
......@@ -13,6 +13,7 @@ using System.Linq;
using System.Reflection;
using RimWorld;
using Verse;
using Verse.Steam;
namespace Glitterworld_Prime
{
......@@ -20,14 +21,23 @@ namespace Glitterworld_Prime
{
#region Fields
public static readonly Assembly Reference = typeof(Utilities).Assembly;
public static readonly Version Version = Reference.GetName().Version;
private static readonly Assembly Reference = typeof(Utilities).Assembly;
public static readonly System.Version Version = Reference.GetName().Version;
private static string _steamId = null;
#endregion
#region Methods
internal static bool TryDropGoodsOnMap(List<GlitterWorldItem> toDrop, Map mapOrderWasPlaced,
internal static string GetUserSteamId()
{
if (_steamId != null) return _steamId;
_steamId = SteamManager.Initialized ? Steamworks.SteamUser.GetSteamID().ToString() : "";
return _steamId;
}
internal static bool TryDropGoodsOnMap(IEnumerable<GlitterWorldItem> toDrop, Map mapOrderWasPlaced,
out IntVec3 landingZone)
{
landingZone = IntVec3.Zero;
......@@ -82,7 +92,7 @@ namespace Glitterworld_Prime
return dropHadErrors;
}
internal static IEnumerable<string> ComputeItemsMadeFromStuff(ThingDef thing,
private static IEnumerable<string> ComputeItemsMadeFromStuff(ThingDef thing,
Dictionary<StuffCategoryDef, List<ThingDef>> stuffData)
{
foreach (var category in thing.stuffCategories)
......@@ -92,10 +102,10 @@ namespace Glitterworld_Prime
}
}
internal static IEnumerable<string> ComputeItemsMadeFromStuffWithQuality(ThingDef thing,
private static IEnumerable<string> ComputeItemsMadeFromStuffWithQuality(ThingDef thing,
Dictionary<StuffCategoryDef, List<ThingDef>> stuffData)
{
for (var quality = 3; quality < 9; quality++)
for (var quality = 3; quality < 7; quality++)
foreach (var category in thing.stuffCategories)
{
var stuffThings = stuffData[category];
......@@ -105,9 +115,9 @@ namespace Glitterworld_Prime
}
}
internal static IEnumerable<string> ComputeItemsWithQuality(ThingDef thing)
private static IEnumerable<string> ComputeItemsWithQuality(ThingDef thing)
{
for (var quality = 3; quality < 9; quality++)
for (var quality = 3; quality < 7; quality++)
yield return thing.defName + ":" + Enum.GetName(typeof(QualityCategory), quality);
}
......@@ -139,17 +149,14 @@ namespace Glitterworld_Prime
internal static Faction GetColonyFaction()
{
foreach (var f in Find.FactionManager.AllFactions)
if (f.IsPlayer)
return f;
return null;
return Find.FactionManager.AllFactions.FirstOrDefault(f => f.IsPlayer);
}
internal static string GetCurrentMapName(Map m)
{
foreach (var fb in Find.WorldObjects.FactionBases.Where(x => x.Faction == Faction.OfPlayer))
foreach (var fb in Find.WorldObjects.SettlementBases.Where(x => x.Faction == Faction.OfPlayer))
if (fb.HasMap && fb.Map == m)
return fb.Name;
return fb.Label;
return "A Colony";
}
......@@ -176,21 +183,15 @@ namespace Glitterworld_Prime
internal static bool HasBaseNameBeenSet(Map m)
{
foreach (var fb in Find.WorldObjects.FactionBases.Where(x => x.Faction == Faction.OfPlayer))
if (fb.HasMap && fb.Map == m && fb.namedByPlayer)
return true;
return false;
return Find.WorldObjects.SettlementBases.Where(x => x.Faction == Faction.OfPlayer).Any(fb => fb.HasMap && fb.Map == m && fb.Faction.HasName);
}
internal static void SetTradablesPrice()
{
if (TradeSession.Active && TradeSession.trader.GetType() == typeof(TraderPrime))
{
// Use reflection to access list of tradeables from the deal since there is no public way to access them.
// This way we don't have to use HugsLib to patch the methods or re-implement the whole trade system.
var tradables = (List<Tradeable>) typeof(TradeDeal)
.GetField("tradeables", BindingFlags.NonPublic | BindingFlags.Instance)
.GetValue(TradeSession.deal);
// We no longer have to use reflection. Hurray!
var tradables = TradeSession.deal.AllTradeables;
//LogWriter.WriteMessage("Dumping trader to log.");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment