本文整理汇总了C#中Thing.SplitOff方法的典型用法代码示例。如果您正苦于以下问题:C# Thing.SplitOff方法的具体用法?C# Thing.SplitOff怎么用?C# Thing.SplitOff使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Thing
的用法示例。
在下文中一共展示了Thing.SplitOff方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryPlaceDirect
// duplicated to make changes (added container support)
public bool TryPlaceDirect(Thing thing, IntVec3 loc, out Thing resultingThing)
{
// boolean success indicator
bool flag = false;
// container code part
List<Thing> list = Find.ThingGrid.ThingsListAt(loc);
if (list.Exists(storage => storage.TryGetComp<CompContainer>() != null))
{
resultingThing = null;
// stackables (like resources)
if (thing.def.stackLimit > 1)
{
foreach (Thing item in list)
{
if (!item.CanStackWith(thing))
{
continue;
}
// if item can stack with another
else
{
// Required, because thing reference is changed to the absorber, if absorbed
Thing t = thing;
if (item.TryAbsorbStack(thing, true))
{
// Clean up to prevent haulables lists overflow
RemoveHaulableFromLists(t);
// it gets absorbed and destroyed
resultingThing = item;
return !flag;
}
}
}
}
resultingThing = GenSpawn.Spawn(thing, loc);
// Clean up to prevent haulables lists overflow
RemoveHaulableFromLists(thing);
return !flag;
}
// vanilla code part
if (thing.stackCount > thing.def.stackLimit)
{
thing = thing.SplitOff(thing.def.stackLimit);
flag = true;
}
if (thing.def.stackLimit > 1)
{
List<Thing> thingList = loc.GetThingList();
int i = 0;
while (i < thingList.Count)
{
Thing thing2 = thingList[i];
if (!thing2.CanStackWith(thing))
{
i++;
}
else
{
// Required, because thing reference is changed to the absorber, if absorbed
Thing t = thing;
if (thing2.TryAbsorbStack(thing, true))
{
// Clean up to prevent haulables lists overflow
RemoveHaulableFromLists(t);
resultingThing = thing2;
return !flag;
}
resultingThing = null;
return false;
}
}
}
resultingThing = GenSpawn.Spawn(thing, loc);
// Clean up to prevent haulables lists overflow
RemoveHaulableFromLists(thing);
SlotGroup slotGroup1 = loc.GetSlotGroup();
if (slotGroup1 != null && slotGroup1.parent != null)
{
slotGroup1.parent.Notify_ReceivedThing(resultingThing);
}
return !flag;
}
示例2: ReceiveThing
public bool ReceiveThing(Thing thingToReceive)
{
if (thingToReceive != null && !thingToReceive.IsChunk())
{
if (compWarehouse != null) compWarehouse.buffer.RemoveAll(x => x == thingToReceive);
foreach (IntVec3 cellReceiving in parent.OccupiedRect().Cells)
{
if (cellReceiving.AllowedToAccept(parent.Map, thingToReceive)
&& cellReceiving.Priority(parent.Map) >= thingToReceive.Position.Priority(parent.Map))
{
IntVec3 thingToReceiveCell = thingToReceive.Position;
List<Thing> thingsReceiving = cellReceiving.GetItemList(parent.Map);
if (thingsReceiving.Count < maxStacks
&& thingToReceive.stackCount > 0)
{
thingToReceiveCell.ThrowDustPuff(parent.Map);
Thing thing = GenSpawn.Spawn(thingToReceive.SplitOff(thingToReceive.stackCount), cellReceiving, parent.Map);
cellReceiving.DropSound(parent.Map, thing.def);
SlotGroup slotGroup = cellReceiving.GetSlotGroup(parent.Map);
if (slotGroup != null && slotGroup.parent != null)
{
slotGroup.parent.Notify_ReceivedThing(thing);
}
return true;
}
else
{
foreach (Thing thingReceiving in thingsReceiving)
{
if (thingReceiving.CanAbsorb(thingToReceive))
{
int thingReceivingStackCount = thingReceiving.stackCount;
if (thingReceiving.TryAbsorbStack(thingToReceive, true))
{
thingToReceiveCell.ThrowDustPuff(parent.Map);
}
if (thingReceivingStackCount != thingReceiving.stackCount)
{
ForbidUtility.SetForbidden(thingReceiving, false, false);
cellReceiving.DropSound(parent.Map, thingReceiving.def);
}
return true;
}
}
}
}
}
}
return false;
}
示例3: TryPlaceDirect
// allows to place items to container stacks
public static bool TryPlaceDirect(Thing thing, IntVec3 loc, out Thing resultingThing,
Action<Thing, int> placedAction = null)
{
#region CONTAINER CASE
var container =
Find.ThingGrid.ThingsListAt(loc).Find(building => building is Container && building.Spawned) as
Container;
if (container != null)
{
// stackables (like resources)
if (thing.def.stackLimit > 1)
{
foreach (var item in container.StoredItems)
{
// if item can stack with another
// Required, because thing reference is changed to the absorber, if absorbed
if (item.TryAbsorbStack(thing, true))
{
// former item gets absorbed and destroyed
resultingThing = item;
// hide texture and label of the stored item
container.HideItem(resultingThing);
return true;
}
}
}
resultingThing = GenSpawn.Spawn(thing, loc);
// hide texture and label of the stored item
container.HideItem(resultingThing);
return true;
}
#endregion
#region VANILLA CASE
// used to keep original thing reference
var initialThing = thing;
var flag = false;
if (thing.stackCount > thing.def.stackLimit)
{
thing = thing.SplitOff(thing.def.stackLimit);
flag = true;
}
if (thing.def.stackLimit > 1)
{
var thingList = loc.GetThingList();
var i = 0;
while (i < thingList.Count)
{
var thing3 = thingList[i];
if (!thing3.CanStackWith(thing))
{
i++;
}
else
{
var stackCount = thing.stackCount;
if (thing3.TryAbsorbStack(thing, true))
{
resultingThing = thing3;
placedAction?.Invoke(thing3, stackCount);
return !flag;
}
resultingThing = null;
if (placedAction != null && stackCount != thing.stackCount)
{
placedAction(thing3, stackCount - thing.stackCount);
}
if (initialThing != thing)
{
initialThing.TryAbsorbStack(thing, false);
}
return false;
}
}
}
resultingThing = GenSpawn.Spawn(thing, loc);
placedAction?.Invoke(thing, thing.stackCount);
var slotGroup = loc.GetSlotGroup();
slotGroup?.parent?.Notify_ReceivedThing(resultingThing);
return !flag;
#endregion
}